From patchwork Fri Dec 14 21:53:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Waiman Long X-Patchwork-Id: 10731705 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 89DB6746 for ; Fri, 14 Dec 2018 21:53:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3CC992D7EE for ; Fri, 14 Dec 2018 21:53:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 30E382D7F8; Fri, 14 Dec 2018 21:53:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C59D42D7E2 for ; Fri, 14 Dec 2018 21:53:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3DD1F8E0212; Fri, 14 Dec 2018 16:53:22 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 3B1E98E01DC; Fri, 14 Dec 2018 16:53:22 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2A2888E0212; Fri, 14 Dec 2018 16:53:22 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by kanga.kvack.org (Postfix) with ESMTP id F1B7E8E01DC for ; Fri, 14 Dec 2018 16:53:21 -0500 (EST) Received: by mail-qt1-f200.google.com with SMTP id z6so6891510qtj.21 for ; Fri, 14 Dec 2018 13:53:21 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=mlGwKIY/E9SCB+00js2v/xNWhVvGerrcKO1O55Kntjc=; b=rdzZPh/Sb4naT9pK2swt04gzcVILonN9Vk6/PN6zIIeSixLqIIxDjAPEX8NTm4XcJj +Re+ZGbJHMK0LFsctLZDoWnWNEflUPSL1X6By9mj3r5S/v8rgyfS+Gg8tpl/xLnsHXbH 2IETs6zt//PxRDBW5k8FVEFeRbmJ9iA30/JMOlgi31yMSmAewRM65OtnorYpRNXfXBED Fo0wEVtmSzwDIazP5SqTHj/iO/HYzy9j/RbuLZYyXd5LlOuDeXl0bSWpGAjJN8cCs4Fv 5upP7Ok5obyWkIFE7qzBdZTYWI2xkMwRedzjWWYrE6kbybE2kGlp/48oJ6JpxU8wd+Uk Gk+w== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of longman@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=longman@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Gm-Message-State: AA+aEWbTE/utZCk35I3Yimpwbpm4xpZLmzpdM/WV+HFZVkDoQ//ODPT4 CQ2gXwb0RlyJ7uItz1nCaE25qfjDoLb1XmADDdKkNRLTsBMzARwD3V19VRzy466OA/tzhn2FtZa LtTpy8V1qihpl8Ee8qVFirMZyq7estvjIT5a7/9YoLVlqlHvjqpCiYubH3Ghevh5yTA== X-Received: by 2002:ac8:4a8e:: with SMTP id l14mr4577697qtq.135.1544824401746; Fri, 14 Dec 2018 13:53:21 -0800 (PST) X-Google-Smtp-Source: AFSGD/XwlwFyjXXd9ESto+YXt20wHxGyd2eb4tNUsl83w84hYBcyVOJ7LFrcTHJu/wvH3KgjOPKT X-Received: by 2002:ac8:4a8e:: with SMTP id l14mr4577686qtq.135.1544824401226; Fri, 14 Dec 2018 13:53:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544824401; cv=none; d=google.com; s=arc-20160816; b=NWeDEGerg94tJEYOS6g7qoeHME2nRkt8KHmEEugQkfPDNIbq0G1eXMFJkPInaJi7h2 +1EHQWGSdFe447ZRHXQXPodzo3kXNNdupfskTZnKNSBh528DNpo2OhVTKdIVU98neixm LIus3ReFxEZWq3FHIMFNsGPbjnXIMh6qT/SNJUoQXmpmGWhLpPGqdQt9UrWjHKgiKbzm Fwtkrpqkg/Cene03FT5Y0CLO/akB8crf9JegFSgVKqTwiJwcM+CoKUWYnZU930c9sqZQ dhpkvEzBrGRVf2/N2uq3CvjFZtkryYgjGGPXu1GqJ3X0qX1XsRTtQQHd6w48EP1LXAOU OhtQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=mlGwKIY/E9SCB+00js2v/xNWhVvGerrcKO1O55Kntjc=; b=CtJ+DC42B2N2Rh78UKCkUOIj5qyvwmB9axdb6isNvFVoceHNyg2a50PPcQ1+R0m0BK VCKKihYEid6hH1/GdglO7HlVcS6Yh/IiDUyPifBgbshFMvBJXB5jD5fZ/FhAU6vW12E+ 5RUqpOH+KNHfnJmiMmGpHIccQsvSP65jkeunai3MjgToDVaGrwADFXPeiCeWi8aNNYxM sNOt+T7JGexqWKj/o6BUW5tLhmCc5goobTVYqdcx/OUJ0q+Ux31i86iTIisp2pZ6UJDt 3sH2mc+6N6eaqoaL4ZtaT219MrigvvgNfHjK+HYj+yU2JlcqctvMo+ub2AU5q+GmUccO EIFw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of longman@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=longman@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id t64si3253694qkf.154.2018.12.14.13.53.21 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 14 Dec 2018 13:53:21 -0800 (PST) Received-SPF: pass (google.com: domain of longman@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of longman@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=longman@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 098A67FD63; Fri, 14 Dec 2018 21:53:20 +0000 (UTC) Received: from llong.com (dhcp-17-223.bos.redhat.com [10.18.17.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id F27DD18111; Fri, 14 Dec 2018 21:53:17 +0000 (UTC) From: Waiman Long To: Alexander Viro , Jonathan Corbet , Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-doc@vger.kernel.org, "Luis R. Rodriguez" , Kees Cook , Linus Torvalds , Jan Kara , "Paul E. McKenney" , Ingo Molnar , Miklos Szeredi , Matthew Wilcox , Larry Woodman , James Bottomley , "Wangkai (Kevin C)" , Michal Hocko , Waiman Long , stable@vger.kernel.org Subject: [RESEND PATCH v4 1/3] fs/dcache: Fix incorrect nr_dentry_unused accounting in shrink_dcache_sb() Date: Fri, 14 Dec 2018 16:53:02 -0500 Message-Id: <1544824384-17668-2-git-send-email-longman@redhat.com> In-Reply-To: <1544824384-17668-1-git-send-email-longman@redhat.com> References: <1544824384-17668-1-git-send-email-longman@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 14 Dec 2018 21:53:20 +0000 (UTC) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP The nr_dentry_unused per-cpu counter tracks dentries in both the LRU lists and the shrink lists where the DCACHE_LRU_LIST bit is set. The shrink_dcache_sb() function moves dentries from the LRU list to a shrink list and subtracts the dentry count from nr_dentry_unused. This is incorrect as the nr_dentry_unused count Will also be decremented in shrink_dentry_list() via d_shrink_del(). To fix this double decrement, the decrement in the shrink_dcache_sb() function is taken out. Fixes: 4e717f5c1083 ("list_lru: remove special case function list_lru_dispose_all." Cc: stable@vger.kernel.org Signed-off-by: Waiman Long Reviewed-by: Dave Chinner --- fs/dcache.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/fs/dcache.c b/fs/dcache.c index 2593153..44e5652 100644 --- a/fs/dcache.c +++ b/fs/dcache.c @@ -1188,15 +1188,11 @@ static enum lru_status dentry_lru_isolate_shrink(struct list_head *item, */ void shrink_dcache_sb(struct super_block *sb) { - long freed; - do { LIST_HEAD(dispose); - freed = list_lru_walk(&sb->s_dentry_lru, + list_lru_walk(&sb->s_dentry_lru, dentry_lru_isolate_shrink, &dispose, 1024); - - this_cpu_sub(nr_dentry_unused, freed); shrink_dentry_list(&dispose); } while (list_lru_count(&sb->s_dentry_lru) > 0); } From patchwork Fri Dec 14 21:53:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Waiman Long X-Patchwork-Id: 10731707 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 58E0413BF for ; Fri, 14 Dec 2018 21:53:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 094622D7E2 for ; Fri, 14 Dec 2018 21:53:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F1B672D7F8; Fri, 14 Dec 2018 21:53:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9456F2D7E2 for ; Fri, 14 Dec 2018 21:53:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 624E98E0213; Fri, 14 Dec 2018 16:53:27 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 5D4E48E01DC; Fri, 14 Dec 2018 16:53:27 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4C3B28E0213; Fri, 14 Dec 2018 16:53:27 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by kanga.kvack.org (Postfix) with ESMTP id 2390B8E01DC for ; Fri, 14 Dec 2018 16:53:27 -0500 (EST) Received: by mail-qk1-f199.google.com with SMTP id s19so6364891qke.20 for ; Fri, 14 Dec 2018 13:53:27 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=wAHg/cHf7b7cDpOwId4v3ytZOHnf9Ex/duOfIooY0+c=; b=IDBDRIiySOWA9KKFpatvMaXhEuGKuJEauUEItAcQxD2rxbt0x+hVhjBzwhE7wLEVH6 RL6BkZ318l6KSfM2wXc483UxzJCn3ws4wPeSi2QLA8XcPE13/2WY+CVULGy5wRdIPpO4 FF+aq6GYCS/aaFD47nStq2VxMcmeuh3/D78Q3y1RMeBK6KFBX79YXV0b6/hrycWqw7bN 6RsGTEZUm2BPAwsqOUTHeqoFTNq1AzCtRxhB/v8Oe0ZmOwAgxlcUinD6R8xSHt6uCsej m7NoUJs6hT512uf6Krl4OwbILUF+TnqAmV1sK/68o/4jmMcUSvaHIoZF4HNqgqF/IIv2 ORPA== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of longman@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=longman@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Gm-Message-State: AA+aEWbVtsSBYcgCrT1LFN5rTmUYW9GZS8M4kI8SKUCm30m0Te+gQ2sl hJDYdve5J7kjjEEQ3qF8YNcaMsbZR8P8tnS6MjPsdoidTlE1m5/thfXOw2RvK6pr/KV2dpLTnaF kov1ckYLUdq4tq2GM2dMNy9Z+V66tHcjYIzHuxmP2mjpLg72AH4VTJcBtTy+zLS3JRg== X-Received: by 2002:a37:4892:: with SMTP id v140mr4276654qka.71.1544824406888; Fri, 14 Dec 2018 13:53:26 -0800 (PST) X-Google-Smtp-Source: AFSGD/WFOf5PPdPqHTpmvEM7yMUJFXvYqd/hfJ07S+ClOJqp7+3a5foPb2i1oJEDbC7Akx+r4t1H X-Received: by 2002:a37:4892:: with SMTP id v140mr4276640qka.71.1544824406387; Fri, 14 Dec 2018 13:53:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544824406; cv=none; d=google.com; s=arc-20160816; b=UWHTvkazfEh2lxcQOuPCm7FUpXBTIdHvamsnWoa0RzdZO7N2eTW2T0kTceojrD0N4Q 11fn/ujmthmOQDhBEccUOUvDmUjuRtRh2zbEv7ocJ3vq1942UteSOfPncEDt+gYXx7IC mtQpKZSijB/yxqSEwmmUzR+MggIoXFTbcf05yaqnNutXa22LTKuk2f3cdl9XwMuSwNit PADD8eCm7l2Ji9VwdaqrQ/0A8AB03DVzTeWDojTBMARYkoLtFKgli3F0Nvfhe0T87xtS 7x33aZv7jz0QJUscSxhboJxfIMwmQ/ezpeD55aCsssC911fWIiYAefyrfWwsfr1gjYqT kOUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=wAHg/cHf7b7cDpOwId4v3ytZOHnf9Ex/duOfIooY0+c=; b=Yf4HVPU+5M+jVVdmD/z2ayLGp68l9Jq5zC/AKy4HwHu45bg0B44Hai9Pd783Kevh38 EOmmU/A7KaHd+XoZw8sPsLAi5Ak5YNCyBZr09oe9CuE+RrOqQPFq3D34+aZPtxGqaDrM yq1mj+CFOobl1sAMmvdcFla/vGb2+NbNt7BGqLqDvxT1gwNYJCgjmkTst4PfXffbnRvr Ou2KbFZbGHT9CA8w6ZtI4XNdBSfs6/yGAvVe+wmsAZH8g0Yul9TteOkIQgMaXpOjohAp xSG48ZHZRL+c773EceFZ23XuXCFQVqaUV7u7LhjLdge0BxHLOXzNUTVqLm9L/OQVS539 IUdA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of longman@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=longman@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id g16si3653152qtg.304.2018.12.14.13.53.26 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 14 Dec 2018 13:53:26 -0800 (PST) Received-SPF: pass (google.com: domain of longman@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of longman@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=longman@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 630D4420B3; Fri, 14 Dec 2018 21:53:25 +0000 (UTC) Received: from llong.com (dhcp-17-223.bos.redhat.com [10.18.17.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2339060C54; Fri, 14 Dec 2018 21:53:20 +0000 (UTC) From: Waiman Long To: Alexander Viro , Jonathan Corbet , Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-doc@vger.kernel.org, "Luis R. Rodriguez" , Kees Cook , Linus Torvalds , Jan Kara , "Paul E. McKenney" , Ingo Molnar , Miklos Szeredi , Matthew Wilcox , Larry Woodman , James Bottomley , "Wangkai (Kevin C)" , Michal Hocko , Waiman Long Subject: [RESEND PATCH v4 2/3] fs: Don't need to put list_lru into its own cacheline Date: Fri, 14 Dec 2018 16:53:03 -0500 Message-Id: <1544824384-17668-3-git-send-email-longman@redhat.com> In-Reply-To: <1544824384-17668-1-git-send-email-longman@redhat.com> References: <1544824384-17668-1-git-send-email-longman@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Fri, 14 Dec 2018 21:53:25 +0000 (UTC) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP The list_lru structure is essentially just a pointer to a table of per-node LRU lists. Even if CONFIG_MEMCG_KMEM is defined, the list field is just used for LRU list registration and shrinker_id is set at initialization. Those fields won't need to be touched that often. So there is no point to make the list_lru structures to sit in their own cachelines. Signed-off-by: Waiman Long Reviewed-by: Dave Chinner --- include/linux/fs.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/include/linux/fs.h b/include/linux/fs.h index c95c080..7707c4a 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1474,11 +1474,12 @@ struct super_block { struct user_namespace *s_user_ns; /* - * Keep the lru lists last in the structure so they always sit on their - * own individual cachelines. + * The list_lru structure is essentially just a pointer to a table + * of per-node lru lists, each of which has its own spinlock. + * There is no need to put them into separate cachelines. */ - struct list_lru s_dentry_lru ____cacheline_aligned_in_smp; - struct list_lru s_inode_lru ____cacheline_aligned_in_smp; + struct list_lru s_dentry_lru; + struct list_lru s_inode_lru; struct rcu_head rcu; struct work_struct destroy_work; From patchwork Fri Dec 14 21:53:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Waiman Long X-Patchwork-Id: 10731709 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 47C23746 for ; Fri, 14 Dec 2018 21:53:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EDF652D7E2 for ; Fri, 14 Dec 2018 21:53:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DF6FF2D7F8; Fri, 14 Dec 2018 21:53:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1BA752D7E2 for ; Fri, 14 Dec 2018 21:53:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 674828E0214; Fri, 14 Dec 2018 16:53:30 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 5D63F8E01DC; Fri, 14 Dec 2018 16:53:30 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 475C88E0214; Fri, 14 Dec 2018 16:53:30 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by kanga.kvack.org (Postfix) with ESMTP id 1975E8E01DC for ; Fri, 14 Dec 2018 16:53:30 -0500 (EST) Received: by mail-qk1-f200.google.com with SMTP id i37so6311971qkh.21 for ; Fri, 14 Dec 2018 13:53:30 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=Zvr/25sjUglqOodKIBI93iej4LJQYQuAUckPFhdAqQ8=; b=JWr+LFfrskT1/FQI5SDqhrWTQ1/hqugSPsIkDhQDZJ+QZeW/PTD2/+XlJWGkafKq6h npr+h6WDYwCCzsdZ771MtZmakLCRZdaqHVB+bkMoCcily6Uz1bTOmeQ+SOxYuoQ1Re2+ A5F3oMvqqVbuniio28n25y39ufkrp6bPqNuaSk24tEa5CRra9oQ1gbWbmibCxTKCXXnT erzVkBsPaumtF1O9JCepPYoH/R5k3udWC9EqDbY7fENNiQXAFQtx5UZhh9ItdNIKbN6g EprOZ+PYbOLzBXjRl7veIHKMfvkjhIiQ7Oh0TO6tdxNBvh07q1BgTa/PgX/nsQX3/klo 80aw== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of longman@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=longman@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Gm-Message-State: AA+aEWZu6F3w3v2nswSgBcf1QDkJ0orzZnU8lurhafDA1t2D0XHzwkEE 2hpZ80sjjes2lBQCtKo3V0xEQMwN7isCfjiMrFwNTWMr1mn0Hny79TyDLOXmJuBzyBE6FLT8YIA qOn63/empW1n/VMBBE6A1UN635lxw6P0dmPDLX9kfggnvhETXnjQLs5L/8QurYuI8iw== X-Received: by 2002:aed:2cc4:: with SMTP id g62mr4619298qtd.192.1544824409816; Fri, 14 Dec 2018 13:53:29 -0800 (PST) X-Google-Smtp-Source: AFSGD/UkE5BEeD94Q9W3OS2IJRr0a0ciDWKKtaPkHZluV9XXpoByhYbX+MakPcrFeDlIxHsgA3hN X-Received: by 2002:aed:2cc4:: with SMTP id g62mr4619266qtd.192.1544824409001; Fri, 14 Dec 2018 13:53:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544824408; cv=none; d=google.com; s=arc-20160816; b=NcAglh7R3PW4DMnMLBa2hqaQdnYFPhp7Ky5jTUP5xYA0gCU1k/l9Sh0Zf/90H/9DJF 4WwbrXkONlzh9a+GBZw1TeN8CQ6RbNQkLxiVQVOk0F16ocWu0TDYjT8BOE2WKC1oLcSq BkhMjRUF9YSSW21mGPhdHCDSBK7Ts/V03KHM6+ZB5MpKvMwZBXyOZRkJBnAZ93H0uRBw fQCfX9IYiyXypcXE6hX4Upxtf7vkRKZQGnZlgvWPBy/w3AcKUHBsx+r14NOHkX5q3Gh2 C16geAypnTCADkkpkI+oiVmIUthe4/fZ0tR63wR2iunyHmGTZXr+jtMbuX7sjSQAzsvo 5yFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=Zvr/25sjUglqOodKIBI93iej4LJQYQuAUckPFhdAqQ8=; b=r/efdP5XtXB2ZGf0DRD0Nf4rdXY3WUTWCOh4lcMZaYpzKcW4ItkxHBbO2l2CaVBYhx hdih4naOfI2cSqj6Qwv03EopjCVQP7ftR9UWf5x8Wx9XKwXxs06mAEholEDCc3ZVq7Qc O0bNy6kWtR+zPwv+KLwx5c4xJwssNG5eA+0K77z65K2hC0AgTEcbZRYrv5TyMtos4G+a kjO9WOLjSsBcvhjX2PEFBDYgzFlQtRqr2a3DnLMtVwDexAoGBzDxDTEpURqdOoi1R/aF CFVSz7/Ztn0QCh8srC0MuNYl9lImD86pTrCmZzGcSfE63ML4o+Vb8wV5dTuKI9gHDKaQ Hrag== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of longman@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=longman@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id q7si3238745qvc.195.2018.12.14.13.53.28 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 14 Dec 2018 13:53:28 -0800 (PST) Received-SPF: pass (google.com: domain of longman@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of longman@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=longman@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 08A53C057F36; Fri, 14 Dec 2018 21:53:28 +0000 (UTC) Received: from llong.com (dhcp-17-223.bos.redhat.com [10.18.17.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8196E5FCD0; Fri, 14 Dec 2018 21:53:25 +0000 (UTC) From: Waiman Long To: Alexander Viro , Jonathan Corbet , Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-doc@vger.kernel.org, "Luis R. Rodriguez" , Kees Cook , Linus Torvalds , Jan Kara , "Paul E. McKenney" , Ingo Molnar , Miklos Szeredi , Matthew Wilcox , Larry Woodman , James Bottomley , "Wangkai (Kevin C)" , Michal Hocko , Waiman Long Subject: [RESEND PATCH v4 3/3] fs/dcache: Track & report number of negative dentries Date: Fri, 14 Dec 2018 16:53:04 -0500 Message-Id: <1544824384-17668-4-git-send-email-longman@redhat.com> In-Reply-To: <1544824384-17668-1-git-send-email-longman@redhat.com> References: <1544824384-17668-1-git-send-email-longman@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 14 Dec 2018 21:53:28 +0000 (UTC) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP The current dentry number tracking code doesn't distinguish between positive & negative dentries. It just reports the total number of dentries in the LRU lists. As excessive number of negative dentries can have an impact on system performance, it will be wise to track the number of positive and negative dentries separately. This patch adds tracking for the total number of negative dentries in the system LRU lists and reports it in the 5th field in the /proc/sys/fs/dentry-state file. The number, however, does not include negative dentries that are in flight but not in the LRU yet as well as those in the shrinker lists which are on the way out anyway. The number of positive dentries in the LRU lists can be roughly found by subtracting the number of negative dentries from the unused count. Matthew Wilcox had confirmed that since the introduction of the dentry_stat structure in 2.1.60, the dummy array was there, probably for future extension. They were not replacements of pre-existing fields. So no sane applications that read the value of /proc/sys/fs/dentry-state will do dummy thing if the last 2 fields of the sysctl parameter are not zero. IOW, it will be safe to use one of the dummy array entry for negative dentry count. Signed-off-by: Waiman Long --- Documentation/sysctl/fs.txt | 26 ++++++++++++++++---------- fs/dcache.c | 32 ++++++++++++++++++++++++++++++++ include/linux/dcache.h | 7 ++++--- 3 files changed, 52 insertions(+), 13 deletions(-) diff --git a/Documentation/sysctl/fs.txt b/Documentation/sysctl/fs.txt index 819caf8..58649bd 100644 --- a/Documentation/sysctl/fs.txt +++ b/Documentation/sysctl/fs.txt @@ -56,26 +56,32 @@ of any kernel data structures. dentry-state: -From linux/fs/dentry.c: +From linux/include/linux/dcache.h: -------------------------------------------------------------- -struct { +struct dentry_stat_t dentry_stat { int nr_dentry; int nr_unused; int age_limit; /* age in seconds */ int want_pages; /* pages requested by system */ - int dummy[2]; -} dentry_stat = {0, 0, 45, 0,}; --------------------------------------------------------------- - -Dentries are dynamically allocated and deallocated, and -nr_dentry seems to be 0 all the time. Hence it's safe to -assume that only nr_unused, age_limit and want_pages are -used. Nr_unused seems to be exactly what its name says. + int nr_negative; /* # of unused negative dentries */ + int dummy; /* Reserved for future use */ +}; +-------------------------------------------------------------- + +Dentries are dynamically allocated and deallocated. + +nr_dentry shows the total number of dentries allocated (active ++ unused). nr_unused shows the number of dentries that are not +actively used, but are saved in the LRU list for future reuse. + Age_limit is the age in seconds after which dcache entries can be reclaimed when memory is short and want_pages is nonzero when shrink_dcache_pages() has been called and the dcache isn't pruned yet. +nr_negative shows the number of unused dentries that are also +negative dentries which do not mapped to actual files. + ============================================================== dquot-max & dquot-nr: diff --git a/fs/dcache.c b/fs/dcache.c index 44e5652..aac41ad 100644 --- a/fs/dcache.c +++ b/fs/dcache.c @@ -119,6 +119,7 @@ struct dentry_stat_t dentry_stat = { static DEFINE_PER_CPU(long, nr_dentry); static DEFINE_PER_CPU(long, nr_dentry_unused); +static DEFINE_PER_CPU(long, nr_dentry_negative); #if defined(CONFIG_SYSCTL) && defined(CONFIG_PROC_FS) @@ -152,11 +153,22 @@ static long get_nr_dentry_unused(void) return sum < 0 ? 0 : sum; } +static long get_nr_dentry_negative(void) +{ + int i; + long sum = 0; + + for_each_possible_cpu(i) + sum += per_cpu(nr_dentry_negative, i); + return sum < 0 ? 0 : sum; +} + int proc_nr_dentry(struct ctl_table *table, int write, void __user *buffer, size_t *lenp, loff_t *ppos) { dentry_stat.nr_dentry = get_nr_dentry(); dentry_stat.nr_unused = get_nr_dentry_unused(); + dentry_stat.nr_negative = get_nr_dentry_negative(); return proc_doulongvec_minmax(table, write, buffer, lenp, ppos); } #endif @@ -317,6 +329,8 @@ static inline void __d_clear_type_and_inode(struct dentry *dentry) flags &= ~(DCACHE_ENTRY_TYPE | DCACHE_FALLTHRU); WRITE_ONCE(dentry->d_flags, flags); dentry->d_inode = NULL; + if (dentry->d_flags & DCACHE_LRU_LIST) + this_cpu_inc(nr_dentry_negative); } static void dentry_free(struct dentry *dentry) @@ -371,6 +385,11 @@ static void dentry_unlink_inode(struct dentry * dentry) * The per-cpu "nr_dentry_unused" counters are updated with * the DCACHE_LRU_LIST bit. * + * The per-cpu "nr_dentry_negative" counters are only updated + * when deleted from or added to the per-superblock LRU list, not + * from/to the shrink list. That is to avoid an unneeded dec/inc + * pair when moving from LRU to shrink list in select_collect(). + * * These helper functions make sure we always follow the * rules. d_lock must be held by the caller. */ @@ -380,6 +399,8 @@ static void d_lru_add(struct dentry *dentry) D_FLAG_VERIFY(dentry, 0); dentry->d_flags |= DCACHE_LRU_LIST; this_cpu_inc(nr_dentry_unused); + if (d_is_negative(dentry)) + this_cpu_inc(nr_dentry_negative); WARN_ON_ONCE(!list_lru_add(&dentry->d_sb->s_dentry_lru, &dentry->d_lru)); } @@ -388,6 +409,8 @@ static void d_lru_del(struct dentry *dentry) D_FLAG_VERIFY(dentry, DCACHE_LRU_LIST); dentry->d_flags &= ~DCACHE_LRU_LIST; this_cpu_dec(nr_dentry_unused); + if (d_is_negative(dentry)) + this_cpu_dec(nr_dentry_negative); WARN_ON_ONCE(!list_lru_del(&dentry->d_sb->s_dentry_lru, &dentry->d_lru)); } @@ -418,6 +441,8 @@ static void d_lru_isolate(struct list_lru_one *lru, struct dentry *dentry) D_FLAG_VERIFY(dentry, DCACHE_LRU_LIST); dentry->d_flags &= ~DCACHE_LRU_LIST; this_cpu_dec(nr_dentry_unused); + if (d_is_negative(dentry)) + this_cpu_dec(nr_dentry_negative); list_lru_isolate(lru, &dentry->d_lru); } @@ -426,6 +451,8 @@ static void d_lru_shrink_move(struct list_lru_one *lru, struct dentry *dentry, { D_FLAG_VERIFY(dentry, DCACHE_LRU_LIST); dentry->d_flags |= DCACHE_SHRINK_LIST; + if (d_is_negative(dentry)) + this_cpu_dec(nr_dentry_negative); list_lru_isolate_move(lru, &dentry->d_lru, list); } @@ -1816,6 +1843,11 @@ static void __d_instantiate(struct dentry *dentry, struct inode *inode) WARN_ON(d_in_lookup(dentry)); spin_lock(&dentry->d_lock); + /* + * Decrement negative dentry count if it was in the LRU list. + */ + if (dentry->d_flags & DCACHE_LRU_LIST) + this_cpu_dec(nr_dentry_negative); hlist_add_head(&dentry->d_u.d_alias, &inode->i_dentry); raw_write_seqcount_begin(&dentry->d_seq); __d_set_inode_and_type(dentry, inode, add_flags); diff --git a/include/linux/dcache.h b/include/linux/dcache.h index ef4b70f..60996e6 100644 --- a/include/linux/dcache.h +++ b/include/linux/dcache.h @@ -62,9 +62,10 @@ struct qstr { struct dentry_stat_t { long nr_dentry; long nr_unused; - long age_limit; /* age in seconds */ - long want_pages; /* pages requested by system */ - long dummy[2]; + long age_limit; /* age in seconds */ + long want_pages; /* pages requested by system */ + long nr_negative; /* # of unused negative dentries */ + long dummy; /* Reserved for future use */ }; extern struct dentry_stat_t dentry_stat;