Re: [PATCH v6 01/13] mm/demotion: Add support for explicit memory tiers

From: Aneesh Kumar K.V
Date: Tue Jun 14 2022 - 04:21:06 EST


Ying Huang <ying.huang@xxxxxxxxx> writes:

....
>
>> All those functions are called with memory_tier_lock_held. Infact all
>> list operations requires that lock held. What details do you suggest we
>> document? I can add extra comment to the mutex itself? Adding locking
>> details to all the functions will be duplicating the same details at
>> multiple places?
>
> memory_tier_lock isn't held to call register_memory_tier() in this
> patch. That will cause confusion.

will this help to explain this better
modified mm/memory-tiers.c
@@ -151,6 +151,11 @@ static void insert_memory_tier(struct memory_tier *memtier)
struct list_head *ent;
struct memory_tier *tmp_memtier;

+ if (IS_ENABLED(CONFIG_DEBUG_VM) && !mutex_is_locked(&memory_tier_lock)) {
+ WARN_ON_ONCE(1);
+ return;
+ }
+
list_for_each(ent, &memory_tiers) {
tmp_memtier = list_entry(ent, struct memory_tier, list);
if (tmp_memtier->rank < memtier->rank) {
@@ -811,8 +816,12 @@ static int __init memory_tier_init(void)

/*
* Register only default memory tier to hide all empty
- * memory tier from sysfs.
+ * memory tier from sysfs. Since this is early during
+ * boot, we could avoid holding memtory_tier_lock. But
+ * keep it simple by holding locks. We can add lock
+ * held debug checks in other functions.
*/
+ mutex_lock(&memory_tier_lock);
memtier = register_memory_tier(DEFAULT_MEMORY_TIER,
get_rank_from_tier(DEFAULT_MEMORY_TIER));

@@ -828,6 +837,7 @@ static int __init memory_tier_init(void)
NODE_DATA(node)->memtier = memtier;
node_set(node, memtier->nodelist);
}
+ mutex_unlock(&memory_tier_lock);
migrate_on_reclaim_init();

return 0;

-aneesh