From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id F2ABFC28D13 for ; Thu, 25 Aug 2022 09:48:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 57B9D940007; Thu, 25 Aug 2022 05:48:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5045B6B0075; Thu, 25 Aug 2022 05:48:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3A580940007; Thu, 25 Aug 2022 05:48:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 29B856B0074 for ; Thu, 25 Aug 2022 05:48:52 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 0022880974 for ; Thu, 25 Aug 2022 09:48:51 +0000 (UTC) X-FDA: 79837640862.06.0C35AD7 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf15.hostedemail.com (Postfix) with ESMTP id 57AF6A0004 for ; Thu, 25 Aug 2022 09:48:51 +0000 (UTC) Received: from dggpemm500021.china.huawei.com (unknown [172.30.72.54]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4MCykN4JL2z1N7Zs; Thu, 25 Aug 2022 17:45:16 +0800 (CST) Received: from dggpemm500001.china.huawei.com (7.185.36.107) by dggpemm500021.china.huawei.com (7.185.36.109) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Thu, 25 Aug 2022 17:48:47 +0800 Received: from [10.174.177.243] (10.174.177.243) by dggpemm500001.china.huawei.com (7.185.36.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Thu, 25 Aug 2022 17:48:47 +0800 Message-ID: Date: Thu, 25 Aug 2022 17:48:46 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 Subject: Re: [PATCH 2/2] mm: slince possible data races about pgdat->kswapd Content-Language: en-US To: David Hildenbrand , Andrew Morton , CC: , References: <20220824071909.192535-1-wangkefeng.wang@huawei.com> <20220824071909.192535-2-wangkefeng.wang@huawei.com> <76d906e8-4c2b-0832-dc43-5fb49b5c6cc5@redhat.com> From: Kefeng Wang In-Reply-To: <76d906e8-4c2b-0832-dc43-5fb49b5c6cc5@redhat.com> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.174.177.243] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm500001.china.huawei.com (7.185.36.107) X-CFilter-Loop: Reflected ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1661420931; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vfTntH06/sa5IiZTKvbzJcRuon6gkeqwMHBEJbatE1I=; b=I0xRm9w9TSbrK7SUA5/v9IXkzSp9csMYXcs0AaYNj1kfCOPzqNDwIUqfIkxIwsJcui1sfx AWqCLhSlcc6/m0aBq7T14NUeo4YPaYjIYNsHSyCGAzqq7BC66/P2YqGFIiqShdvgR8CVSd r4D76b+kzw8MXlXaIpFeQMhe/x+6jlU= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf15.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1661420931; a=rsa-sha256; cv=none; b=VxOYP8wecyCZ3T12R7WnWrcnesjuuCOsARYQItUvnGXHCNSNrqbXosK35LTwVU7ZyS1W8t EBihhWte+xU4uOmFehtBpLPzepH4XCbNslS//iF6YOinkdOT0YNTUVRov7IW2yIT/7TJni dRRpX8BBgnC564wD0J7rGNvWWEtesls= Authentication-Results: imf15.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf15.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com X-Rspam-User: X-Rspamd-Queue-Id: 57AF6A0004 X-Rspamd-Server: rspam10 X-Stat-Signature: 7qun3bmgf5437ab88iqc3bcy3hi6ssuo X-HE-Tag: 1661420931-98228 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: On 2022/8/25 16:22, David Hildenbrand wrote: > On 25.08.22 04:34, Kefeng Wang wrote: >> On 2022/8/24 16:24, David Hildenbrand wrote: >>> On 24.08.22 09:19, Kefeng Wang wrote: >>>> The pgdat->kswapd could be accessed concurrently by kswapd_run() and >>>> kcompactd(), it don't be protected by any lock, which could leads to >>>> data races, adding READ/WRITE_ONCE() to slince it. >>> Okay, I think this patch here makes it clearer that we really just want >>> proper synchronization instead of hacking around it. >>> >>> What speaks against protecting pgdat->kswapd this using some proper >>> locking primitive? >> as comments about kswapd in struct pglist_data,  pgdat->kswapd should be >> >> protected by mem_hotplug_begin/done(), how about this way? >> >> diff --git a/mm/compaction.c b/mm/compaction.c >> index 640fa76228dd..62018f35242a 100644 >> --- a/mm/compaction.c >> +++ b/mm/compaction.c >> @@ -1983,7 +1983,13 @@ static inline bool is_via_compact_memory(int order) >> >>  static bool kswapd_is_running(pg_data_t *pgdat) >>  { >> -       return pgdat->kswapd && task_is_running(pgdat->kswapd); >> +       bool running; >> + >> +       mem_hotplug_begin(); >> +       running = pgdat->kswapd && task_is_running(pgdat->kswapd); >> +       mem_hotplug_end(); >> + >> +       return running; >>  } > I'd much rather just use a dedicated lock that does not involve memory > hotplug. The issue only occurred due memory hotplug, without mem-hotplug, the kswapd won't stop or re-run, there is no above issue too, add a new lock would be duplicated, but the scope of protection is smaller, I could repost with new lock if no more comment. > >