Received: by 2002:ac0:950c:0:0:0:0:0 with SMTP id f12csp3536651imc; Wed, 13 Mar 2019 22:33:00 -0700 (PDT) X-Google-Smtp-Source: APXvYqz5diBzKXUMzMpJJxpxCSep1RGMXodvd2kHkvduzWLctlcwDVYUgmxFIA5JLVcRs/0d4b6c X-Received: by 2002:a17:902:42d:: with SMTP id 42mr50787267ple.229.1552541580157; Wed, 13 Mar 2019 22:33:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552541580; cv=none; d=google.com; s=arc-20160816; b=KLeOkrM/b9i8Pw7iCIyslUYlBvlk9KVu+A+oYXd/DDaj5ET6AgExtLU/M1FfZFF0eh +0vhhxMfff1w+OkZTqn9Y+QtoSLrhjCXgrRguz0q0sJLRIrhVmidzc1sLUht0HPkDJRm s3AwjxngD1d8YPCZSnVjG8UmM02CPXkEypVAGLWJSFkJNQV0eKK1IlVyMydI1IrbBftj m7qqri4tDXvYLNEgQmiKlhDILOVLI/ZrK3R1/SSy53U5pAtkcrFiIzlYlSKbTeSx1HQw deWWBxAAIKSIVSjGvJ9fDBj4XUYD/fS9YCWJXzGhgjA8qu/RL0HooTPeYFEE5W7EqZxO m7Qg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=sj6M4OpXGBRvDdAJeVq0+fK1eLMRQBJtoq/YI75189Q=; b=fKLzDmsYMKhN0z76urJM7/47JM+hRZE/OK9cZw2Jzhpif+RA/m+Kpqc1yYDkT1THil H02a3O1Wr1xFpdmVR7iTmRZxgVeTPU/NZS5YXFMyHOS18thj0svtGfZERT+EeTh4zSWp z8TkD3Qjmsm3bbG4jj4dK3iPZhiEJDp5nhamNOoMw0fjdW66kiS1UI1ZhGmbM2HP4SQS nk9ztxJrlQwcg4Y+7ZsqxS6Ns1ZDNveS7n0oSqNTwpE/NvJSWog2n+Y2iyoUgAwsbx8A Kt8KJxq9jrjB9u/Ka13ySc4+aI9VdSWG7Mt1O+m2pZefUP7WZ48iCucPaE5VI70xUszg cLGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=TSUpdgdJ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m6si9242552pls.436.2019.03.13.22.32.44; Wed, 13 Mar 2019 22:33:00 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=TSUpdgdJ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727022AbfCNFcQ (ORCPT + 99 others); Thu, 14 Mar 2019 01:32:16 -0400 Received: from out2-smtp.messagingengine.com ([66.111.4.26]:40215 "EHLO out2-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726130AbfCNFcO (ORCPT ); Thu, 14 Mar 2019 01:32:14 -0400 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id D451E214E0; Thu, 14 Mar 2019 01:32:12 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Thu, 14 Mar 2019 01:32:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; bh=sj6M4OpXGBRvDdAJeVq0+fK1eLMRQBJtoq/YI75189Q=; b=TSUpdgdJ U3GaOh+0VR06/UhiUqmiX9hT+6ZjnnXKAd/Js9+MTL0QgE1EHJdHHK2qiVbaKqz+ 9x/aceEGdIi5Zx7jY0XgDwspMLIXFwIfN1fCI7XImr8D9a9K4ZgsSYi77c6i93+6 Ne30IQLGZ8vdDHvEYK2BFfQdGZwgvVs5UcGp5qQiiRecuE5qAvK/2pzWolFGTbAV oA8l06zPSt2HkHj8SJDWOqf0noK8QjPFzw49MmzYcV8mYQbEBBVmWD78jWlTCCk8 TOwjKGiJ38u6yR/RusWV0dMP7X6q7SW4jHeHuNRv10Dyv9UXLraivrZe7fksUEAL RbDhew6o9XGaLw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedutddrhedugdekgecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvffufffkofgjfhgggfestdekredtredttdenucfhrhhomhepfdfvohgsihhn ucevrdcujfgrrhguihhnghdfuceothhosghinheskhgvrhhnvghlrdhorhhgqeenucfkph epuddvgedrudeiledrvdefrddukeegnecurfgrrhgrmhepmhgrihhlfhhrohhmpehtohgs ihhnsehkvghrnhgvlhdrohhrghenucevlhhushhtvghrufhiiigvpedu X-ME-Proxy: Received: from eros.localdomain (124-169-23-184.dyn.iinet.net.au [124.169.23.184]) by mail.messagingengine.com (Postfix) with ESMTPA id 43937E415C; Thu, 14 Mar 2019 01:32:08 -0400 (EDT) From: "Tobin C. Harding" To: Andrew Morton Cc: "Tobin C. Harding" , Roman Gushchin , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Matthew Wilcox , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 2/7] slob: Respect list_head abstraction layer Date: Thu, 14 Mar 2019 16:31:30 +1100 Message-Id: <20190314053135.1541-3-tobin@kernel.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190314053135.1541-1-tobin@kernel.org> References: <20190314053135.1541-1-tobin@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently we reach inside the list_head. This is a violation of the layer of abstraction provided by the list_head. It makes the code fragile. More importantly it makes the code wicked hard to understand. The code logic is based on the page in which an allocation was made, we want to modify the slob_list we are working on to have this page at the front. We already have a function to check if an entry is at the front of the list. Recently a function was added to list.h to do the list rotation. We can use these two functions to reduce line count, reduce code fragility, and reduce cognitive load required to read the code. Use list_head functions to interact with lists thereby maintaining the abstraction provided by the list_head structure. Signed-off-by: Tobin C. Harding --- I verified the comment pointing to Knuth, the page number may be out of date but with this comment I was able to find the text that discusses this, left the comment as is (after fixing style). mm/slob.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/mm/slob.c b/mm/slob.c index 307c2c9feb44..39ad9217ffea 100644 --- a/mm/slob.c +++ b/mm/slob.c @@ -268,8 +268,7 @@ static void *slob_page_alloc(struct page *sp, size_t size, int align) */ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node) { - struct page *sp; - struct list_head *prev; + struct page *sp, *prev, *next; struct list_head *slob_list; slob_t *b = NULL; unsigned long flags; @@ -296,18 +295,27 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node) if (sp->units < SLOB_UNITS(size)) continue; + /* + * Cache previous entry because slob_page_alloc() may + * remove sp from slob_list. + */ + prev = list_prev_entry(sp, lru); + /* Attempt to alloc */ - prev = sp->lru.prev; b = slob_page_alloc(sp, size, align); if (!b) continue; - /* Improve fragment distribution and reduce our average + next = list_next_entry(prev, lru); /* This may or may not be sp */ + + /* + * Improve fragment distribution and reduce our average * search time by starting our next search here. (see - * Knuth vol 1, sec 2.5, pg 449) */ - if (prev != slob_list->prev && - slob_list->next != prev->next) - list_move_tail(slob_list, prev->next); + * Knuth vol 1, sec 2.5, pg 449) + */ + if (!list_is_first(&next->lru, slob_list)) + list_rotate_to_front(&next->lru, slob_list); + break; } spin_unlock_irqrestore(&slob_lock, flags); -- 2.21.0