Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp786733pxb; Wed, 20 Jan 2021 22:37:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJxdS/djbUbxFTiKxzHQ5WTPwjqhTwMQDPwK1KtgCtjyY2GhgyRWw1aNPBLVQRoq8wODcoZn X-Received: by 2002:a17:906:1796:: with SMTP id t22mr7925416eje.372.1611211022358; Wed, 20 Jan 2021 22:37:02 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1611211022; cv=pass; d=google.com; s=arc-20160816; b=YKMLBASm153AQmXMjg014t/6kwJQSBOtkkP5LolnEH6BJFduiUMiM+dCJgTlREJ2DE coIhf2GKk/99MsA2Fcz9oWqPrZ/pBidBYgOLKWC9qClhgJlP5tRNYCWvwYNGIqJB3DJC mLoo/jDfoEJStGRVVJmwaLD8a2A9Nsd7lDM9T6y4XoWum2vduIGfODOX4w2d3GN2Vnyz xE4LWJ13B4gqXdM1Z7LfnnVVcpkM2Tr1QBCc6v3o7F5fMACusdTLOls88jSaKKNy5E8Z IpJ9zbyHFUIbCLON6qj+Shzt1vowP8fX8Ld7tdNr3CTXcPxtSTAIgak1xp1XI1e23WWL WNTg== 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=r9TGsCPBLgSvGknUGTaA1ZQbCBgPuOSKLCcLa6W7mEE=; b=UfwNZ5f2joeZ6EQRyBuDGSq8jlkSCKRWHiMGZrikZMHR8CVIXTSpE+lfFZ3DlsZpjL 72Uf9uBHtIi425P6Baec1Exoa7LU9SgxGqlqB5mG64mY+Y6yoxDzAVQJEtiJgNz0F5+S KM8v4Fcx0ZsJ5vKSXOxKxOrvdZasg5q4sahke7Lg5/x94/m2qPejfxZdvDPu1XR+KxRl mCh8dLYsmNrDhnkfVzrd/68k8JXOYItLUaJIx5maOTSrNFu/jrRwxjWG6yk9W95YNgzr SA+VixcTasesmGA6BaCDRALpCxTwoFQbHPiMa4G1cdwAeuqer1ojvGpsL4DdJQYmwVnA eNiA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@windriversystems.onmicrosoft.com header.s=selector2-windriversystems-onmicrosoft-com header.b=b+3uZXYM; 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 bu13si1411419ejb.588.2021.01.20.22.36.38; Wed, 20 Jan 2021 22:37:02 -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=b+3uZXYM; 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 S1726277AbhAUGdz (ORCPT + 99 others); Thu, 21 Jan 2021 01:33:55 -0500 Received: from mail-co1nam11on2047.outbound.protection.outlook.com ([40.107.220.47]:9664 "EHLO NAM11-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727102AbhAUGcw (ORCPT ); Thu, 21 Jan 2021 01:32:52 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LsUVHFLnnMn1ydQLlV/4LrVfsKTqe5tuQPDbco2MX8/6l5SStbESkZZE2pnkRss0B60r02uBOV06UJDuARFOhvcn2MNYK6cBCbemqSTh19NHzCPNDGHAQzU3oqncF4EcAc/lm1l7gdwp+IYBPSoOYObCuVBLp2weziEa5d4RhSo7dVNX3SGVyY99TIobhhoajP81hZKnSuRzhtWS/lQh6Z1+Hs1OHD6hHkN87LbsdJtBrS1p/Qo9gT48bPu6jNB4lcs86Xd2NksDJErR3YL21QyuWnkiaOM4XpCTiN6qAk4kbclSDlFkpgB661nEi0VaUmsYlUPVAeZG2KD+x3/7Dg== 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=r9TGsCPBLgSvGknUGTaA1ZQbCBgPuOSKLCcLa6W7mEE=; b=Domj2HM3zW6jDsmJKWarnNg02CbjwZ+T/pTN7yK8CzdG5qZW03/n4jjTyIYaPLlscaFqUEFwFVRxFT9ZFiWZwjjVueZJLFLPU2YMIFj0wecTH0Fu0hAn9JIU/xzmit//GuSZ1m1vcaTc/T/jo8B8rNdTC2lj2zsywmTIaNpnWRSV97+NMUTpeV8fmFRv0/BEYs45pY7yfUjNTNbHRKEVBZlKPjImNdnVtFihmgusV5z0WfeIfYYYhCvpZklRgznMK7FHQR6jw/y6OulgcpKFSboR3JHvihYFgAPTF5WuGJDkm6Ztcxz78qpijMREAdujYG0DrGDp9wYhagQh7DLxNA== 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=r9TGsCPBLgSvGknUGTaA1ZQbCBgPuOSKLCcLa6W7mEE=; b=b+3uZXYMVQKbASwjjgjrwmQnrEI6yTu77/Oa757voRJsmwm7jgvD1rPBAJg21ExIzpPwHKoHeh6wTikLOnj1UemkAxnQ68c2zG73JLGZndzusHUobYDFN4r2h5FMP94JLdGely8epAuSpdqisN+2DT1ZgCtYn+LOWHm8oX1XMxU= Authentication-Results: kernel.org; dkim=none (message not signed) header.d=none;kernel.org; dmarc=none action=none header.from=windriver.com; Received: from BYAPR11MB2632.namprd11.prod.outlook.com (2603:10b6:a02:c4::17) by SJ0PR11MB5008.namprd11.prod.outlook.com (2603:10b6:a03:2d5::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3763.9; Thu, 21 Jan 2021 06:32:02 +0000 Received: from BYAPR11MB2632.namprd11.prod.outlook.com ([fe80::94a4:4e15:ab64:5006]) by BYAPR11MB2632.namprd11.prod.outlook.com ([fe80::94a4:4e15:ab64:5006%5]) with mapi id 15.20.3763.014; Thu, 21 Jan 2021 06:32:02 +0000 From: qiang.zhang@windriver.com To: paulmck@kernel.org Cc: rcu@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] rcu: Release per-cpu krcp page cache when CPU going offline Date: Thu, 21 Jan 2021 14:49:49 +0800 Message-Id: <20210121064949.16164-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: HK0PR03CA0101.apcprd03.prod.outlook.com (2603:1096:203:b0::17) 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 HK0PR03CA0101.apcprd03.prod.outlook.com (2603:1096:203:b0::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.11 via Frontend Transport; Thu, 21 Jan 2021 06:32:00 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 54f68f6f-6119-40dc-68c2-08d8bdd642f4 X-MS-TrafficTypeDiagnostic: SJ0PR11MB5008: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:126; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: TjdvbGQ8UTu902FhdGDMZn+VmP7tYJQGMyTYxd6GnprXoXZM+IwR/sQoZoDrd04wf1TOFPjzk/fr78lxJeI+Hy2kmeYvWu3p6NmCOZV69MhstiDrIJovODRUj6NDLJGbNtoICdBbaC+xCShiC5PGz9SNi8NJxnmHB0zfzvu3/4J7VSGJwroa+7HJR0C33JOK+1ESjZRMGbwZ8hQhm/teYKrj9WscsFT6VfgTgIqlPMfURJ9cNQ583lR5EAlr7Cl7imUzjUlFNNRxx1/mxYKuCTU9/JiEYBkjiB8PdzwQY70L54xfWGG4kZ9vkvy9MUuk1hGDBWigLP0AficBHgSxaE/qqsgpWbpZRoXf+Uoc/dtFLvpQEKHPqAWQCRYBfo4e 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)(396003)(346002)(136003)(39850400004)(366004)(376002)(5660300002)(26005)(8676002)(83380400001)(956004)(16526019)(478600001)(186003)(6916009)(2906002)(36756003)(4326008)(66476007)(66556008)(2616005)(9686003)(8936002)(6486002)(6512007)(52116002)(1076003)(6506007)(6666004)(66946007)(66574015)(86362001)(316002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?UjotW8rCF1CN2dyT6VYI5ioa7ZNDBV1LPwI2p4qi7jgHneTHzIThQlqKnTkf?= =?us-ascii?Q?qyfnSmLP/c7VYUW13pWEuhy3P44YUddWBF/Ae+E+/ylXEbOYlW1SHVL31S5y?= =?us-ascii?Q?nuZijloEcImtsE7Rfem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river.com X-MS-Exchange-CrossTenant-Network-Message-Id: 54f68f6f-6119-40dc-68c2-08d8bdd642f4 X-MS-Exchange-CrossTenant-AuthSource: BYAPR11MB2632.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Jan 2021 06:32:02.2986 (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: Li0rpPw+wj3FXw92blLnea4zWZdmmFy2bsK/3xxv0n92Vcpc1VKWnoNNZ6f0o2+Kn7QVPkX2z0USCTjCFm4n/TAdh857ljILGxcCvny4C/4= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR11MB5008 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Zqiang If CPUs go offline, the corresponding krcp's page cache can not be use util the CPU come back online, or maybe the CPU will never go online again, this commit therefore free krcp's page cache when CPUs go offline. Signed-off-by: Zqiang --- kernel/rcu/tree.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c index e04e336bee42..2eaf6f287483 100644 --- a/kernel/rcu/tree.c +++ b/kernel/rcu/tree.c @@ -158,6 +158,9 @@ static void sync_sched_exp_online_cleanup(int cpu); static void check_cb_ovld_locked(struct rcu_data *rdp, struct rcu_node *rnp); static bool rcu_rdp_is_offloaded(struct rcu_data *rdp); +static void krc_offline(unsigned int cpu, bool off); +static void free_krc_page_cache(int cpu); + /* rcuc/rcub kthread realtime priority */ static int kthread_prio = IS_ENABLED(CONFIG_RCU_BOOST) ? 1 : 0; module_param(kthread_prio, int, 0444); @@ -2457,6 +2460,9 @@ int rcutree_dead_cpu(unsigned int cpu) // Stop-machine done, so allow nohz_full to disable tick. tick_dep_clear(TICK_DEP_BIT_RCU); + + krc_offline(cpu, true); + free_krc_page_cache(cpu); return 0; } @@ -3169,6 +3175,7 @@ struct kfree_rcu_cpu { struct llist_head bkvcache; int nr_bkv_objs; + bool offline; }; static DEFINE_PER_CPU(struct kfree_rcu_cpu, krc) = { @@ -3220,6 +3227,8 @@ static inline bool put_cached_bnode(struct kfree_rcu_cpu *krcp, struct kvfree_rcu_bulk_data *bnode) { + if (krcp->offline) + return false; // Check the limit. if (krcp->nr_bkv_objs >= rcu_min_cached_objs) return false; @@ -3230,6 +3239,39 @@ put_cached_bnode(struct kfree_rcu_cpu *krcp, } +static void krc_offline(unsigned int cpu, bool off) +{ + unsigned long flags; + struct kfree_rcu_cpu *krcp; + + krcp = per_cpu_ptr(&krc, cpu); + raw_spin_lock_irqsave(&krcp->lock, flags); + if (off) + krcp->offline = true; + else + krcp->offline = false; + raw_spin_unlock_irqrestore(&krcp->lock, flags); +} + +static void free_krc_page_cache(int cpu) +{ + unsigned long flags; + struct kfree_rcu_cpu *krcp; + int i; + struct kvfree_rcu_bulk_data *bnode; + + krcp = per_cpu_ptr(&krc, cpu); + + for (i = 0; i < rcu_min_cached_objs; i++) { + raw_spin_lock_irqsave(&krcp->lock, flags); + bnode = get_cached_bnode(krcp); + raw_spin_unlock_irqrestore(&krcp->lock, flags); + if (!bnode) + break; + free_page((unsigned long)bnode); + } +} + /* * This function is invoked in workqueue context after a grace period. * It frees all the objects queued on ->bhead_free or ->head_free. @@ -3549,7 +3591,8 @@ void kvfree_call_rcu(struct rcu_head *head, rcu_callback_t func) kasan_record_aux_stack(ptr); success = kvfree_call_rcu_add_ptr_to_bulk(krcp, ptr); if (!success) { - run_page_cache_worker(krcp); + if (!krcp->offline) + run_page_cache_worker(krcp); if (head == NULL) // Inline if kvfree_rcu(one_arg) call. @@ -4086,6 +4129,7 @@ int rcutree_prepare_cpu(unsigned int cpu) rcu_spawn_cpu_nocb_kthread(cpu); WRITE_ONCE(rcu_state.n_online_cpus, rcu_state.n_online_cpus + 1); + krc_offline(cpu, false); return 0; } @@ -4591,6 +4635,7 @@ static void __init kfree_rcu_batch_init(void) INIT_DELAYED_WORK(&krcp->monitor_work, kfree_rcu_monitor); INIT_WORK(&krcp->page_cache_work, fill_page_cache_func); krcp->initialized = true; + krcp->offline = true; } if (register_shrinker(&kfree_rcu_shrinker)) pr_err("Failed to register kfree_rcu() shrinker!\n"); -- 2.29.2