Mercurial > nomad > experimental
changeset 1304:b3e0798761b7 draft
objstore: add a page cache lock to serialize accesses to the free lists
Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
author | Josef 'Jeff' Sipek <jeffpc@josefsipek.net> |
---|---|
date | Thu, 01 Feb 2024 11:54:09 -0500 |
parents | 52a373257894 |
children | e74729772b75 |
files | src/objstore/cache.c |
diffstat | 1 files changed, 17 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/objstore/cache.c Thu Feb 01 11:49:46 2024 -0500 +++ b/src/objstore/cache.c Thu Feb 01 11:54:09 2024 -0500 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020,2022 Josef 'Jeff' Sipek <jeffpc@josefsipek.net> + * Copyright (c) 2020,2022,2024 Josef 'Jeff' Sipek <jeffpc@josefsipek.net> * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -25,10 +25,14 @@ #include "objstore_impl.h" +static LOCK_CLASS(page_cache_lc); + +/* constant for the lifetime of the process, no locking necessary */ static size_t npages; static struct page *pages; /* internal lists */ +static struct lock page_cache_lock; static struct list free_pages; /* fully allocated */ static struct list unallocated_pages; /* missing ->ptr */ @@ -42,6 +46,8 @@ if (!pages) return -ENOMEM; + MXINIT(&page_cache_lock, &page_cache_lc); + list_create(&free_pages, sizeof(struct page), offsetof(struct page, pages)); list_create(&unallocated_pages, sizeof(struct page), @@ -64,6 +70,8 @@ } free(pages); + + MXDESTROY(&page_cache_lock); } static int page_cmp(const void *va, const void *vb) @@ -95,6 +103,8 @@ { struct page *page; + MXLOCK(&page_cache_lock); + page = list_head(&free_pages); if (page) { list_remove(&free_pages, page); @@ -115,15 +125,21 @@ out: VERIFY3P(page->ptr, !=, NULL); + MXUNLOCK(&page_cache_lock); + return page; } static void free_page(struct page *page) { + MXLOCK(&page_cache_lock); + if (page->ptr) list_insert_head(&free_pages, page); else list_insert_head(&unallocated_pages, page); + + MXUNLOCK(&page_cache_lock); } struct page *page_lookup(struct objver *ver, uint64_t pgno, int flags)