All of lore.kernel.org
 help / color / mirror / Atom feed
From: Waiman Long <longman@redhat.com>
To: Thomas Gleixner <tglx@linutronix.de>,
	Andrew Morton <akpm@linux-foundation.org>
Cc: linux-kernel@vger.kernel.org,
	Yang Shi <yang.shi@linux.alibaba.com>,
	"Joel Fernandes (Google)" <joel@joelfernandes.org>,
	Qian Cai <cai@gmx.us>, Zhong Jiang <zhongjiang@huawei.com>,
	Waiman Long <longman@redhat.com>
Subject: [PATCH 3/5] debugobjects: Reduce number of pool_lock acquisitions in fill_pool()
Date: Mon, 20 May 2019 10:14:48 -0400	[thread overview]
Message-ID: <20190520141450.7575-4-longman@redhat.com> (raw)
In-Reply-To: <20190520141450.7575-1-longman@redhat.com>

In fill_pool(), the pool_lock is acquired and then released once per
debug object. If many objects are to be filled, the constant lock and
unlock operations are extra overhead. To reduce these overhead, we
batch them up and do an allocation of 4 objects per lock/unlock sequence.

Signed-off-by: Waiman Long <longman@redhat.com>
---
 lib/debugobjects.c | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/lib/debugobjects.c b/lib/debugobjects.c
index c30c9d308e9f..7573c736da7d 100644
--- a/lib/debugobjects.c
+++ b/lib/debugobjects.c
@@ -120,7 +120,7 @@ static const char *obj_states[ODEBUG_STATE_MAX] = {
 static void fill_pool(void)
 {
 	gfp_t gfp = GFP_ATOMIC | __GFP_NORETRY | __GFP_NOWARN;
-	struct debug_obj *new, *obj;
+	struct debug_obj *obj;
 	unsigned long flags;
 
 	if (likely(obj_pool_free >= debug_objects_pool_min_level))
@@ -136,7 +136,7 @@ static void fill_pool(void)
 		 * Recheck with the lock held as the worker thread might have
 		 * won the race and freed the global free list already.
 		 */
-		if (obj_nr_tofree) {
+		while (obj_nr_tofree && (obj_pool_free < obj_pool_min_free)) {
 			obj = hlist_entry(obj_to_free.first, typeof(*obj), node);
 			hlist_del(&obj->node);
 			obj_nr_tofree--;
@@ -150,15 +150,23 @@ static void fill_pool(void)
 		return;
 
 	while (obj_pool_free < debug_objects_pool_min_level) {
+		struct debug_obj *new[ODEBUG_BATCH_SIZE];
+		int cnt;
 
-		new = kmem_cache_zalloc(obj_cache, gfp);
-		if (!new)
+		for (cnt = 0; cnt < ODEBUG_BATCH_SIZE; cnt++) {
+			new[cnt] = kmem_cache_zalloc(obj_cache, gfp);
+			if (!new[cnt])
+				break;
+		}
+		if (!cnt)
 			return;
 
 		raw_spin_lock_irqsave(&pool_lock, flags);
-		hlist_add_head(&new->node, &obj_pool);
-		debug_objects_allocated++;
-		obj_pool_free++;
+		while (cnt) {
+			hlist_add_head(&new[--cnt]->node, &obj_pool);
+			debug_objects_allocated++;
+			obj_pool_free++;
+		}
 		raw_spin_unlock_irqrestore(&pool_lock, flags);
 	}
 }
@@ -280,7 +288,7 @@ static void free_obj_work(struct work_struct *work)
 	/*
 	 * The objs on the pool list might be allocated before the work is
 	 * run, so recheck if pool list it full or not, if not fill pool
-	 * list from the global free list
+	 * list from the global free list.
 	 */
 	while (obj_nr_tofree && obj_pool_free < debug_objects_pool_size) {
 		obj = hlist_entry(obj_to_free.first, typeof(*obj), node);
-- 
2.18.1


  parent reply	other threads:[~2019-05-20 14:15 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-20 14:14 [PATCH 0/5] debugobjects: Reduce global pool_lock contention Waiman Long
2019-05-20 14:14 ` [PATCH 1/5] debugobjects: Add percpu free pools Waiman Long
2019-06-14 12:58   ` [tip:core/debugobjects] " tip-bot for Waiman Long
2019-05-20 14:14 ` [PATCH 2/5] debugobjects: Percpu pool lookahead freeing/allocation Waiman Long
2019-06-14 12:59   ` [tip:core/debugobjects] " tip-bot for Waiman Long
2019-05-20 14:14 ` Waiman Long [this message]
2019-06-14 13:00   ` [tip:core/debugobjects] debugobjects: Reduce number of pool_lock acquisitions in fill_pool() tip-bot for Waiman Long
2019-05-20 14:14 ` [PATCH 4/5] debugobjects: Less aggressive freeing of excess debug objects Waiman Long
2019-06-14 13:01   ` [tip:core/debugobjects] " tip-bot for Waiman Long
2019-05-20 14:14 ` [PATCH 5/5] debugobjects: Move printk out of db lock critical sections Waiman Long
2019-06-14 13:01   ` [tip:core/debugobjects] debugobjects: Move printk out of db->lock " tip-bot for Waiman Long

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190520141450.7575-4-longman@redhat.com \
    --to=longman@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=cai@gmx.us \
    --cc=joel@joelfernandes.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tglx@linutronix.de \
    --cc=yang.shi@linux.alibaba.com \
    --cc=zhongjiang@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.