Skip to contentSkip to conversation

UBC: core (structures, API)

RFC PATCH Oleg Nesterov 2 participants 2 messages Aug 17, 2006

lore
Share & tools
lore
#0 lore raw
Quoted 22 lines · Kirill Korotaev
(quoted diff) +21 -0
+struct user_beancounter *beancounter_findcreate(uid_t uid,
+		struct user_beancounter *p, int mask)
+{
+	struct user_beancounter *new_ub, *ub, *tmpl_ub;
+	unsigned long flags;
+	struct hlist_head *slot;
+	struct hlist_node *pos;
+
+	if (mask & UB_LOOKUP_SUB) {
+		WARN_ON(p == NULL);
+		tmpl_ub = &default_subbeancounter;
+		slot = &ub_hash[ub_subhash_fun(p, uid)];
+	} else {
+		WARN_ON(p != NULL);
+		tmpl_ub = &default_beancounter;
+		slot = &ub_hash[ub_hash_fun(uid)];
+	}
+	new_ub = NULL;
+
+retry:
+	spin_lock_irqsave(&ub_hash_lock, flags);

Review

Quoted 10 lines
(quoted diff) +10 -0
+	hlist_for_each_entry (ub, pos, slot, hash)
+		if (ub->ub_uid == uid && ub->parent == p)
+			break;
+
+	if (pos != NULL) {
+		get_beancounter(ub);
+		spin_unlock_irqrestore(&ub_hash_lock, flags);
+
+		if (new_ub != NULL) {
+			put_beancounter(new_ub->parent);
					^^^^^^^^^^^^^^

Stupid question: why ->parent can't be NULL ? (without UB_LOOKUP_SUB).

Quoted 5 lines
(quoted diff) +5 -0
+	if (mask & UB_ALLOC_ATOMIC) {
+		new_ub = kmem_cache_alloc(ub_cachep, GFP_ATOMIC);
+		if (new_ub == NULL)
+			goto out_unlock;
+

Review

Quoted 10 lines
(quoted diff) +10 -0
+		memcpy(new_ub, tmpl_ub, sizeof(*new_ub));
+		init_beancounter_struct(new_ub, uid);
+		if (p)
+			new_ub->parent = get_beancounter(p);
+		goto out_install;
+	}
+
+	spin_unlock_irqrestore(&ub_hash_lock, flags);
+
+	new_ub = kmem_cache_alloc(ub_cachep, GFP_KERNEL);

beancounter_findcreate() is not time critical, yes? Isn't it better to kill 'if (mask & UB_ALLOC_ATOMIC) { ... }' and just do

	new_ub = kmem_cache_alloc(ub_cachep,
		UB_ALLOC_ATOMIC ? GFP_ATOMIC : GFP_KERNEL);

after spin_unlock(&ub_hash_lock) ?

Oleg.

#1 lore raw

Oleg,

Quoted 34 lines
Quoted 21 lines
(quoted diff) +21 -0
+struct user_beancounter *beancounter_findcreate(uid_t uid,
+		struct user_beancounter *p, int mask)
+{
+	struct user_beancounter *new_ub, *ub, *tmpl_ub;
+	unsigned long flags;
+	struct hlist_head *slot;
+	struct hlist_node *pos;
+
+	if (mask & UB_LOOKUP_SUB) {
+		WARN_ON(p == NULL);
+		tmpl_ub = &default_subbeancounter;
+		slot = &ub_hash[ub_subhash_fun(p, uid)];
+	} else {
+		WARN_ON(p != NULL);
+		tmpl_ub = &default_beancounter;
+		slot = &ub_hash[ub_hash_fun(uid)];
+	}
+	new_ub = NULL;
+
+retry:
+	spin_lock_irqsave(&ub_hash_lock, flags);

Review

Quoted 10 lines
(quoted diff) +10 -0
+	hlist_for_each_entry (ub, pos, slot, hash)
+		if (ub->ub_uid == uid && ub->parent == p)
+			break;
+
+	if (pos != NULL) {
+		get_beancounter(ub);
+		spin_unlock_irqrestore(&ub_hash_lock, flags);
+
+		if (new_ub != NULL) {
+			put_beancounter(new_ub->parent);
					^^^^^^^^^^^^^^
Quoted 1 line

Stupid question: why ->parent can't be NULL ? (without UB_LOOKUP_SUB).

oh, good catch. We removed the check for NULL in put_beancounter() for cleanup, but didn't notice this place. Thanks!

Quoted 20 lines
Quoted 5 lines
(quoted diff) +5 -0
+	if (mask & UB_ALLOC_ATOMIC) {
+		new_ub = kmem_cache_alloc(ub_cachep, GFP_ATOMIC);
+		if (new_ub == NULL)
+			goto out_unlock;
+

Review

Quoted 10 lines
(quoted diff) +10 -0
+		memcpy(new_ub, tmpl_ub, sizeof(*new_ub));
+		init_beancounter_struct(new_ub, uid);
+		if (p)
+			new_ub->parent = get_beancounter(p);
+		goto out_install;
+	}
+
+	spin_unlock_irqrestore(&ub_hash_lock, flags);
+
+	new_ub = kmem_cache_alloc(ub_cachep, GFP_KERNEL);

beancounter_findcreate() is not time critical, yes? Isn't it better to kill 'if (mask & UB_ALLOC_ATOMIC) { ... }' and just do

Quoted 4 lines
	new_ub = kmem_cache_alloc(ub_cachep,
		UB_ALLOC_ATOMIC ? GFP_ATOMIC : GFP_KERNEL);

after spin_unlock(&ub_hash_lock) ?

ok, will do. Thanks for comments!

Kirill