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 78FC3C32774 for ; Thu, 25 Aug 2022 08:22:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AB1F4940008; Thu, 25 Aug 2022 04:22:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A61FD940007; Thu, 25 Aug 2022 04:22:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 928B2940008; Thu, 25 Aug 2022 04:22:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 83DB2940007 for ; Thu, 25 Aug 2022 04:22:24 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 5B34F418A8 for ; Thu, 25 Aug 2022 08:22:24 +0000 (UTC) X-FDA: 79837423008.20.B7F7744 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf06.hostedemail.com (Postfix) with ESMTP id A6D0C180005 for ; Thu, 25 Aug 2022 08:22:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661415743; h=from:from: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=gWsuQmDZ53RMfU7VereuhMyA9Iegsk4DOCD2DeIEmdg=; b=GD4cCaTPIf7n54iWSgNYR1+4dkH3ILMgaQ28LQxp2ISSKlChGhxtqAAPJ48aH8Ym1WNNCx z1mbMhMefysB2M+pTq3RJJ8MaoKi14HlxJxp5yZKQXb1nVowlTzlX1Jido2y7eX6e1ipiV Nfl6MxPBx8ew4iqRKZjXdR7kLff9zdY= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-395-n5O5PketNaC0SGnPK9A17A-1; Thu, 25 Aug 2022 04:22:21 -0400 X-MC-Unique: n5O5PketNaC0SGnPK9A17A-1 Received: by mail-wm1-f70.google.com with SMTP id c64-20020a1c3543000000b003a61987ffb3so10621046wma.6 for ; Thu, 25 Aug 2022 01:22:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc; bh=gWsuQmDZ53RMfU7VereuhMyA9Iegsk4DOCD2DeIEmdg=; b=8RYpInYd8/XwQcIQzJiIaE8TYqRMR/9lmj4qOOdOEMN0ESQIkagEYrLStu7zFWIwmt gYuqQupT4Z1tsXcxZd6V167I+hJof1Ysb0wr1b3VKPqGUOfSGlRzFnE2GQTjfNknrnBl S2G4ptIRZF7UpzACQYS+qJb7qyaWZp/jToJ9Ozc2uoYYUveVL0znBh3n/LxNdMsGznR/ 6rYS5mmUYRh/4J7/voCPqJtehOhEJ2WhMn6968vWuOgiNmhkiOnRpI614P99rpKh+JIA +bCBciQ2PE/pjMp0v+fQIMmfMyJMc6nvMV/aG8A2ylWff95jAkwVkxBz+/qmXYqmP9sJ OVBg== X-Gm-Message-State: ACgBeo3b1mlxaYlPDOX+yJThPUwmZx9AhHyNPM0/esOI2GXEXRNvYFqt ejydcLQOfApr2uZCrB2nqW/heBtogu4xl7wFAbv2vZQofHNkEko9G9VcBzOzhjwvvmC54ikS4A8 mu2vsZh44OCc= X-Received: by 2002:a05:6000:2ca:b0:225:6004:8cf1 with SMTP id o10-20020a05600002ca00b0022560048cf1mr1465539wry.477.1661415740706; Thu, 25 Aug 2022 01:22:20 -0700 (PDT) X-Google-Smtp-Source: AA6agR6jW+15n76wSRMHxT+rAFDODLxyVf6L/Jnd78XG/YAuheLiBF62+F5CbLL+qA9xgxWrpzIkmA== X-Received: by 2002:a05:6000:2ca:b0:225:6004:8cf1 with SMTP id o10-20020a05600002ca00b0022560048cf1mr1465530wry.477.1661415740450; Thu, 25 Aug 2022 01:22:20 -0700 (PDT) Received: from ?IPV6:2a09:80c0:192:0:20af:34be:985b:b6c8? ([2a09:80c0:192:0:20af:34be:985b:b6c8]) by smtp.gmail.com with ESMTPSA id p19-20020a05600c1d9300b003a6077384ecsm4753841wms.31.2022.08.25.01.22.19 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 25 Aug 2022 01:22:19 -0700 (PDT) Message-ID: <76d906e8-4c2b-0832-dc43-5fb49b5c6cc5@redhat.com> Date: Thu, 25 Aug 2022 10:22:19 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.12.0 Subject: Re: [PATCH 2/2] mm: slince possible data races about pgdat->kswapd To: Kefeng Wang , Andrew Morton , linux-mm@kvack.org Cc: muchun.song@linux.dev, linux-kernel@vger.kernel.org References: <20220824071909.192535-1-wangkefeng.wang@huawei.com> <20220824071909.192535-2-wangkefeng.wang@huawei.com> From: David Hildenbrand Organization: Red Hat In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1661415744; 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:dkim-signature; bh=gWsuQmDZ53RMfU7VereuhMyA9Iegsk4DOCD2DeIEmdg=; b=ZsLHKeBCN201lj0zs7Rj0yKSXNq8WSki6yN0ot4/7NYGGpanid5dN0HkjD1vvtN98j1Xw9 NcIp1BtctbWsnQKIeUFvKAnAxdtfxKDsuDTVckOfH9TDbN+/K9YPOckzvgHSPvLjdPNQT+ sxMPPKUCIEGuRpZgmLqJk4jpPemT1tY= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=GD4cCaTP; spf=pass (imf06.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1661415744; a=rsa-sha256; cv=none; b=iKyaxnClfXWAlj/vSftqkkgIfFlXLK55PXkhcDTbcWOJ0ojc+QhCj03y56KUYkfVwSRQqE dGWEK7WELXw9fB3R7/pBa60GqjVTlQ/9QVYDe93x4RUzD6wBxIR7D6dfeAHx4vHf0jnwvh PcibyNadrbvU4U4mXdCJKE1qxgWgfiI= Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=GD4cCaTP; spf=pass (imf06.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspam-User: X-Stat-Signature: nrus3zqeim59ahuzhxp1mtikw49ri9r4 X-Rspamd-Queue-Id: A6D0C180005 X-Rspamd-Server: rspam03 X-HE-Tag: 1661415743-312039 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 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. -- Thanks, David / dhildenb