Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2508709pxb; Sat, 30 Jan 2021 05:04:04 -0800 (PST) X-Google-Smtp-Source: ABdhPJyzh+C8fTc6dHPO2HedgA61EVQtx55An9lMnnCEflU3i3n+ql3YCbZvcfNuPvufKqHY6Ym4 X-Received: by 2002:a05:6402:11d3:: with SMTP id j19mr9929683edw.314.1612011844115; Sat, 30 Jan 2021 05:04:04 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1612011844; cv=pass; d=google.com; s=arc-20160816; b=dHyAgOCKYlobpA0IWA3I/Ior4ZEDpR+X1dK/jJXFoIqGgb7hyvp6AN8UgqVmxQ0tQH ZBoOQaqzrnGhOWGY97jdMEdLfhR/gmblfn/zwEqml74TNLPO23n8BhANqaoYos7Len/H v0e0D4dgffbOJZjU/yAi24S4YPaiKPiYhf5deTmWAlTqsudQbXP5QXO2gOjGLcLdjci8 4H4SnNuVUZxW1ylwmABmBUa6VABRoCAKASb2P0MMVWn+v3xzOAz65EdzDDu7KdjUDBTW tDuvgIVkqlre/sp4QWjb/yc0COuTH989EKKzzr8oWjcmTugeIOIfxUEshPxefCS+PZOR 7vyg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from :dkim-signature; bh=pJiRBoN7CJQ/ETQzIalRqR5gqL72iqIiL/RKYWpu+2g=; b=BAdsNbBqXCUDC7Z38qOMrQGXVLIzUHXlYdzSHJ051IxT7Xz7V3td2MV3uEmITgFOv9 /G3d/9dx7kS4SMF8hyMCToQ9ARAKsZ65WRlyHfPlUapo0rDq1QFhBSJQiSSw7kwRlnie 8P6/O87+zf9Y4Y/cxg46s2BwVWenYsWmqFe+KPHC7fE2IQeN3CWPQZFgiQ/dZ8DP/ufo 3qN+iCgofjzrE9RzVUvsxGJKO9V+m76JbtGv8g0e3oCkHd13bnz+qZUl2U6bdyZUltNk GnT0wLHjzaRPVCM7T4kdWyrvKrx5r3bK+oBFx6tNS7Qh3FBn2RmzmrNcHLJHK5UrgwwF i4xQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@windriversystems.onmicrosoft.com header.s=selector2-windriversystems-onmicrosoft-com header.b=jutWqr+o; arc=pass (i=1 spf=pass spfdomain=windriver.com dkim=pass dkdomain=windriver.com dmarc=pass fromdomain=windriver.com); 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r23si8128547edy.113.2021.01.30.05.03.39; Sat, 30 Jan 2021 05:04:04 -0800 (PST) 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=@windriversystems.onmicrosoft.com header.s=selector2-windriversystems-onmicrosoft-com header.b=jutWqr+o; arc=pass (i=1 spf=pass spfdomain=windriver.com dkim=pass dkdomain=windriver.com dmarc=pass fromdomain=windriver.com); 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231394AbhA3NBk (ORCPT + 99 others); Sat, 30 Jan 2021 08:01:40 -0500 Received: from mail-eopbgr680048.outbound.protection.outlook.com ([40.107.68.48]:48755 "EHLO NAM04-BN3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231228AbhA3NBj (ORCPT ); Sat, 30 Jan 2021 08:01:39 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ESBq9lbIiFHHI8TkgS8epzxVXzr1sZ1HjLLETd9zak8dr5Lz/c9mIo7/425vk3WvmyuMBd8m5Bfg5kIaH/nfoWcKZWB//LPLIFfKrnYH2iOSRNoJRjU7jJecktctLuL70FtRqvGmnoxTMSuTSzYnyAobMIyIWENmM/K2GDgEFBfORRf2puhIxSs3mwgtyc0YfcbcbheWJdpGwYdnMA2vMp63hRXpl8zc8Ly25jhaqARE5FBiOYsi8Mafelwr7sYa7Dx6vaOcmZtVfF1RvYOjL03lWK/6Tm4znIW1GPjXpyG7wvBIuwL2b4VXyjPpkldvEDa3x25D3EZoW+GVvXDWqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=pJiRBoN7CJQ/ETQzIalRqR5gqL72iqIiL/RKYWpu+2g=; b=LGtdAIakngqr3OHcN4TQbLdDPUIgQb/BUVE9hlu4k6RhKUEhrOY3gHAg1rEYRbqiLhwgWiaYF1WYfTWMgTtdWM57dpGw3JALKYmHLyOH0LVdLnxVcAw/5zhwWlMXLfive0nM5O3qokK7WEEe/082WKKx4psPrvX9G17/FmKf1HgYofpKlOIdCXZlZBA0q9FISWMyfJ7Hg7ut3mQgEP4yOZZQqyaKhDVUWMdVkCHwm1oDwgzakScQvFSDAlNe2AoQIXfCkC6UXPZiFjaylvM90lKpD31pzxqTBmRuDkadLDCuX+busPLRk7hauY6lr9RUibnOqs3KQ+GoII4S3c6lWQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=windriver.com; dmarc=pass action=none header.from=windriver.com; dkim=pass header.d=windriver.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=windriversystems.onmicrosoft.com; s=selector2-windriversystems-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=pJiRBoN7CJQ/ETQzIalRqR5gqL72iqIiL/RKYWpu+2g=; b=jutWqr+oGjELeREX+QyN3JhMADcvdymEftojVmZ8WOd5kfD2ZBAUawsP4zaqZVzsT5XcChPYrROQy/E6TR12G3KVJfqs6d647tlHK2aa60R4q8Nm9zT+i08EmGX4QtJeWMHANOMbqS433p5bXE78FoTYAxN7A4b9TKplM9Io0w8= Authentication-Results: gmail.com; dkim=none (message not signed) header.d=none;gmail.com; dmarc=none action=none header.from=windriver.com; Received: from BYAPR11MB2632.namprd11.prod.outlook.com (2603:10b6:a02:c4::17) by BYAPR11MB3352.namprd11.prod.outlook.com (2603:10b6:a03:1d::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.15; Sat, 30 Jan 2021 13:00:55 +0000 Received: from BYAPR11MB2632.namprd11.prod.outlook.com ([fe80::89a3:42c3:6509:4acd]) by BYAPR11MB2632.namprd11.prod.outlook.com ([fe80::89a3:42c3:6509:4acd%4]) with mapi id 15.20.3784.017; Sat, 30 Jan 2021 13:00:54 +0000 From: qiang.zhang@windriver.com To: urezki@gmail.com, paulmck@kernel.org, joel@joelfernandes.org Cc: rcu@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3] kvfree_rcu: Release page cache under memory pressure Date: Sat, 30 Jan 2021 21:18:51 +0800 Message-Id: <20210130131851.23285-1-qiang.zhang@windriver.com> X-Mailer: git-send-email 2.17.1 Content-Type: text/plain X-Originating-IP: [60.247.85.82] X-ClientProxiedBy: HK0PR03CA0108.apcprd03.prod.outlook.com (2603:1096:203:b0::24) To BYAPR11MB2632.namprd11.prod.outlook.com (2603:10b6:a02:c4::17) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from pek-lpg-core1-vm1.wrs.com (60.247.85.82) by HK0PR03CA0108.apcprd03.prod.outlook.com (2603:1096:203:b0::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3805.16 via Frontend Transport; Sat, 30 Jan 2021 13:00:52 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f948e57b-fdab-40bf-ded5-08d8c51f1417 X-MS-TrafficTypeDiagnostic: BYAPR11MB3352: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:883; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: m0wGtuzBiSyO31n+9BW4xM+aHM6qLFkBjJq/lTkMuaQk4SUtZYm8t2Y33JXi7vrd/hbrjZo7tXNOdt8fJT5uzXU2phMf0QYMuWYM73MfieAT+IVaIbnb5LYlkqMygOfpHK8LiV2uwrQdihrQUrRBPYiih1RA88DP53BXBrUgJlar9lX4QoFcXTi2VBh5hLOwc3KzF/IbkL8ZZwkFQGa+sbgV9l+frWFMd6SQKssmcxnt3I9L3cgydjnx/VXvlduBO4wqd63/TsRsdcaEHuivJQioBzkhR4Dw4Nn37T3OFYr9oqFH76QeXUhMKuqAKg00Yoh4qIPbzgPRCk8bPcVj34nOAkvWybGqxV6cKTfVYVezbZWl5oEzewDGYdn7JB/wGQD+pBwMrbY/34Bu36u6yGOeJ3i/4qd16WYwTBENw+IWq2AEGBJPB3jQr9fIfxgeUtvN2qoxGafI9rmgo9RDPiscgAK2CINWkGmsAp8N40Ll0xtoLV0oLrIcY/fMw80kxVq9s/hvzO1Z4cGRscpNOA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BYAPR11MB2632.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(346002)(39850400004)(376002)(136003)(396003)(366004)(956004)(66556008)(6512007)(52116002)(26005)(9686003)(86362001)(8676002)(16526019)(2616005)(66946007)(186003)(66476007)(478600001)(83380400001)(2906002)(6486002)(5660300002)(36756003)(8936002)(316002)(6506007)(4326008)(1076003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?OfOfHBytxW6fC3VHPoLC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ii?Q?S4v01JH4v8ViQnOiaT1susAZUOAX2LepUgUPMW/RcgQFoloXfiTBD6kpx6Cx?= =?us-ascii?Q?4WmIbcJtBgUAzQghQqiJXdhyp6jmABUgBs+x7cokd15636VukJ9sX6/izuFA?= =?us-ascii?Q?l1Vr25pk8KYURQV3rchO5EbnxYa4zOCpiwHNFKFPKQqGagCXgv5TMsU3d3er?= =?us-ascii?Q?4lEaWRZG?= X-OriginatorOrg: windriver.com X-MS-Exchange-CrossTenant-Network-Message-Id: f948e57b-fdab-40bf-ded5-08d8c51f1417 X-MS-Exchange-CrossTenant-AuthSource: BYAPR11MB2632.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jan 2021 13:00:54.7840 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8ddb2873-a1ad-4a18-ae4e-4644631433be X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: T35+FNocrNr6Fm3RSQUfS1PO9EpNtkyNcPFjRkrZ6VPJQzYSHoq8gJOo5oKx9M2e2hXK9hc4/CO1SI3UQeTfrBgwlr8oBYrsncKTaRXZ0rs= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR11MB3352 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Zqiang Add free per-cpu existing krcp's page cache operation, when the system is under memory pressure. Signed-off-by: Zqiang --- kernel/rcu/tree.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c index c1ae1e52f638..644b0f3c7b9f 100644 --- a/kernel/rcu/tree.c +++ b/kernel/rcu/tree.c @@ -3571,17 +3571,41 @@ void kvfree_call_rcu(struct rcu_head *head, rcu_callback_t func) } EXPORT_SYMBOL_GPL(kvfree_call_rcu); +static int free_krc_page_cache(struct kfree_rcu_cpu *krcp) +{ + unsigned long flags; + struct llist_node *page_list, *pos, *n; + int freed = 0; + + raw_spin_lock_irqsave(&krcp->lock, flags); + page_list = llist_del_all(&krcp->bkvcache); + krcp->nr_bkv_objs = 0; + raw_spin_unlock_irqrestore(&krcp->lock, flags); + + llist_for_each_safe(pos, n, page_list) { + free_page((unsigned long)pos); + freed++; + } + + return freed; +} + static unsigned long kfree_rcu_shrink_count(struct shrinker *shrink, struct shrink_control *sc) { int cpu; unsigned long count = 0; + unsigned long flags; /* Snapshot count of all CPUs */ for_each_possible_cpu(cpu) { struct kfree_rcu_cpu *krcp = per_cpu_ptr(&krc, cpu); count += READ_ONCE(krcp->count); + + raw_spin_lock_irqsave(&krcp->lock, flags); + count += krcp->nr_bkv_objs; + raw_spin_unlock_irqrestore(&krcp->lock, flags); } return count; @@ -3598,6 +3622,8 @@ kfree_rcu_shrink_scan(struct shrinker *shrink, struct shrink_control *sc) struct kfree_rcu_cpu *krcp = per_cpu_ptr(&krc, cpu); count = krcp->count; + count += free_krc_page_cache(krcp); + raw_spin_lock_irqsave(&krcp->lock, flags); if (krcp->monitor_todo) kfree_rcu_drain_unlock(krcp, flags); -- 2.17.1