Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp1858726pxb; Mon, 23 Aug 2021 06:26:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwehv7AZBNu1AirSE9otK3BL5aRywWxeHLQn0jM3vHJ5xcCegGLITRBEi6pMIJKkt+z5DLZ X-Received: by 2002:a05:6e02:d03:: with SMTP id g3mr23140375ilj.127.1629725199046; Mon, 23 Aug 2021 06:26:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629725199; cv=none; d=google.com; s=arc-20160816; b=ld50CpGSYwbu67S2FOWLzEq3FKO+0C5OyvM5bhgMLIfSiH2m/zp+f2pINGZlMxghH0 ZiN6057nPKNCRJX2yjyPNy2xDJW4/7SXbHC446ZE+/Bv6mGijP+DSzzDAqJu4DEkGLKc 5FJS1w578ObsUe+NMPTk6lJQYOgz+Sicviy7A5NBnlNOQFzbzCWtfhe6nq21GHm+sG6D 7Vh2dDyJ3x+0reT2VH6/vPj7O7lGM+aY3lnpBn2hspaVs1dzPkPFF8BIB+U2sjEoOzmv jkaMFXl41apaTI5WfYierV8bRB4AAZNSefScITNbukZGwmYE5S7xx0/7PVz9V+B9nxOS zX0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=bhCPWDwZQK45935V6guIQPPOMVjXya8oOiZ7LeV5bA0=; b=GCZ+gGRHXFCaOasMxusOWraMbRxzqOwDpWHHi5/QwO5+BXEg9JBStAb5oIIBfKzV3I rWSalT5Wi6djOsRXwue/rmZXbS/PDDxkRnUfCIH8+Po1UNfoRXFvGlrQkQaDr/7Obu8r W8Ws71iHZDJL8Cz6mTWY7Gb0fJ0vVgd/4LjgyNRh13iHLFAXK6gcYwSLHkLnu42SffN3 F2ZV2d0QYRNSsqLBafQGZcGs3FcAgx60v5CVKhTQC/5ergXg+6IgSYjIBYTrSjx3Vy1H 9ChamMYxlt8hAAzIQC9bWg9EIhJ6CsX7EPCDxPgMsD8yEOXu2I7CktNdupBKWgI5jTLM EH6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=VQFYCpzY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v13si15457586ilh.9.2021.08.23.06.26.27; Mon, 23 Aug 2021 06:26:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=VQFYCpzY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237416AbhHWN0M (ORCPT + 99 others); Mon, 23 Aug 2021 09:26:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:44140 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237417AbhHWN0L (ORCPT ); Mon, 23 Aug 2021 09:26:11 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 91480613B3; Mon, 23 Aug 2021 13:25:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1629725128; bh=UwkfhY8SJENE/3Lw6o/UNr99bPnMhT2qywo7ZC7jJ0U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VQFYCpzYlt6wfhC07qVjVyQ26BGSfkzav/X2l3c4xoJUQKTk+i9m4hGIOnLQo/EiA bp2iQFFiJYYwQDBU4R8w5ffo/DANj5ZNHYrDa0kvJYoF8GXLSBcd2aY4oFe7oZpBzr oCzpZju4iPm6OakMMeTi9OGmNANojNoKq3/E5dahg6GJbZYpNZO2986JM9oLQiW1Mn WSq8x09c/u08Hpne4ir8wELaj3TROdnH9WI3sxcifTS73TfZLi+W55cHEN28a4PLDk 1M++HnIxZnSO7tmqsxgKgVxpWCZ3rLnWHV2I0XhA94B8oI39cN/sMjRFIh6SGySAom WEQOAusF3NVHw== From: Mike Rapoport To: linux-mm@kvack.org Cc: Andrew Morton , Andy Lutomirski , Dave Hansen , Ira Weiny , Kees Cook , Mike Rapoport , Mike Rapoport , Peter Zijlstra , Rick Edgecombe , Vlastimil Babka , x86@kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 2/4] list: Support list head not in object for list_lru Date: Mon, 23 Aug 2021 16:25:11 +0300 Message-Id: <20210823132513.15836-3-rppt@kernel.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20210823132513.15836-1-rppt@kernel.org> References: <20210823132513.15836-1-rppt@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Rick Edgecombe In future patches, there will be a need to keep track of objects with list_lru where the list_head is not in the object (will be in struct page). Since list_lru automatically determines the node id from the list_head, this will fail when using struct page. So create a new function in list_lru, list_lru_add_node(), that allows the node id of the item to be passed in. Otherwise it behaves exactly like list_lru_add(). Signed-off-by: Rick Edgecombe --- include/linux/list_lru.h | 13 +++++++++++++ mm/list_lru.c | 10 ++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/include/linux/list_lru.h b/include/linux/list_lru.h index 08e07c19fd13..42c22322058b 100644 --- a/include/linux/list_lru.h +++ b/include/linux/list_lru.h @@ -90,6 +90,19 @@ void memcg_drain_all_list_lrus(int src_idx, struct mem_cgroup *dst_memcg); */ bool list_lru_add(struct list_lru *lru, struct list_head *item); +/** + * list_lru_add_node: add an element to the lru list's tail + * @list_lru: the lru pointer + * @item: the item to be added. + * @nid: the node id of the item + * + * Like list_lru_add, but takes the node id as parameter instead of + * calculating it from the list_head passed in. + * + * Return value: true if the list was updated, false otherwise + */ +bool list_lru_add_node(struct list_lru *lru, struct list_head *item, int nid); + /** * list_lru_del: delete an element to the lru list * @list_lru: the lru pointer diff --git a/mm/list_lru.c b/mm/list_lru.c index c1bec58168e1..f35f11ada8a1 100644 --- a/mm/list_lru.c +++ b/mm/list_lru.c @@ -112,9 +112,8 @@ list_lru_from_kmem(struct list_lru_node *nlru, void *ptr, } #endif /* CONFIG_MEMCG_KMEM */ -bool list_lru_add(struct list_lru *lru, struct list_head *item) +bool list_lru_add_node(struct list_lru *lru, struct list_head *item, int nid) { - int nid = page_to_nid(virt_to_page(item)); struct list_lru_node *nlru = &lru->node[nid]; struct mem_cgroup *memcg; struct list_lru_one *l; @@ -134,6 +133,13 @@ bool list_lru_add(struct list_lru *lru, struct list_head *item) spin_unlock(&nlru->lock); return false; } + +bool list_lru_add(struct list_lru *lru, struct list_head *item) +{ + int nid = page_to_nid(virt_to_page(item)); + + return list_lru_add_node(lru, item, nid); +} EXPORT_SYMBOL_GPL(list_lru_add); bool list_lru_del(struct list_lru *lru, struct list_head *item) -- 2.28.0