Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp225572imu; Thu, 8 Nov 2018 00:33:51 -0800 (PST) X-Google-Smtp-Source: AJdET5fFnaGIE8llGJlyXeChi6Fj2EaDBblqHYYq4KOaPpB6bvnUh6ic3R0SWRWQIDuqJwXAge+F X-Received: by 2002:a63:e445:: with SMTP id i5mr3057809pgk.307.1541666031756; Thu, 08 Nov 2018 00:33:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541666031; cv=none; d=google.com; s=arc-20160816; b=PB6nlLyh6/biuCpPT0jMGGlXtg8e0HtVUPuZTzExK2igKD6TFKyglVwJp69giFQkcH 6xPqE0Dmtjg8uqJn42oFgbrmN57r2gtTE2jXI1f7TuVC+mLonjzzEjBuIbYHL7fZSbbK 1KmcaQLpn9CJQmWHiEE57vcHk8gLfJ6i7dK/THxv1cXKvcpKZzPozIFoVhGQeqknMPe+ 7+VAdB0IiSRnpMa6V3dXHQHq3gtm4HWA8kHluS98q8Q2V490SO30jAd8VqtobQ7C1e3q jwRktsixQ7y+8BsZim1cnp5/YPO4Q1Gc3CAqGWvRY3CpFz+c5EOTmHAQbmtY9KPEurQd HNhw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=TKDsGOP0MdBIw5bW8ie4/2TaSJWSNQh1y8RwQUv6BhY=; b=CSYaXYIN9BliR/DZ/NVm0zYtH+IBRkbjkBp0miMLmSDpXXXZ+47ws5Io+Q3fowD1Fd bAxZYS8/e3G4QdMxUAMY3IREcPWUMMYJVXl0UxIoVFRMOWIueuwtsTt/sUEwNhHcFHO8 bM0ntdKeXpTSYDjIQHf5+2ws6QQ1VUeie7DCMYKRZU11vrZX7ZSeUbAt7f6uGjorE6d3 OUa1AGeQ84w8siUKw/mqr3YaYLbet0+EbnAn8d+1jhvSRINu4zovWR3epn7ujJqqI2sE aaWQYDFZ/TMXOYLKxm5h4W51cd7RNujcF0atJUDyrbW4wbqpqgY3RglCC8rxxuf3S/KQ 1YUQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j19-v6si3408654pfh.63.2018.11.08.00.33.35; Thu, 08 Nov 2018 00:33:51 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726620AbeKHSHX (ORCPT + 99 others); Thu, 8 Nov 2018 13:07:23 -0500 Received: from mx2.suse.de ([195.135.220.15]:37856 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726143AbeKHSHX (ORCPT ); Thu, 8 Nov 2018 13:07:23 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 9FB7BAE12; Thu, 8 Nov 2018 08:32:58 +0000 (UTC) Date: Thu, 8 Nov 2018 09:32:58 +0100 From: Michal Hocko To: Arun KS Cc: akpm@linux-foundation.org, keescook@chromium.org, khlebnikov@yandex-team.ru, minchan@kernel.org, vbabka@suse.cz, osalvador@suse.de, linux-kernel@vger.kernel.org, linux-mm@kvack.org, getarunks@gmail.com Subject: Re: [PATCH v3 2/4] mm: convert zone->managed_pages to atomic variable Message-ID: <20181108083258.GP27423@dhcp22.suse.cz> References: <1541665398-29925-1-git-send-email-arunks@codeaurora.org> <1541665398-29925-3-git-send-email-arunks@codeaurora.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1541665398-29925-3-git-send-email-arunks@codeaurora.org> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu 08-11-18 13:53:16, Arun KS wrote: > totalram_pages, zone->managed_pages and totalhigh_pages updates > are protected by managed_page_count_lock, but readers never care > about it. Convert these variables to atomic to avoid readers > potentially seeing a store tear. > > This patch converts zone->managed_pages. Subsequent patches will > convert totalram_panges, totalhigh_pages and eventually > managed_page_count_lock will be removed. > > Suggested-by: Michal Hocko > Suggested-by: Vlastimil Babka > Signed-off-by: Arun KS > Reviewed-by: Konstantin Khlebnikov > Acked-by: Michal Hocko > Acked-by: Vlastimil Babka > > --- > Main motivation was that managed_page_count_lock handling was > complicating things. It was discussed in lenght here, > https://lore.kernel.org/patchwork/patch/995739/#1181785 > So it seemes better to remove the lock and convert variables > to atomic, with preventing poteintial store-to-read tearing as > a bonus. Do not be afraid to put this into the changelog. It is much better to have it there in case anybody wonders in future and use git blame rather than chase an email archive to find it in the foot note. The same applies to the meta patch. > Most of the changes are done by below coccinelle script, > > @@ > struct zone *z; > expression e1; > @@ > ( > - z->managed_pages = e1 > + atomic_long_set(&z->managed_pages, e1) > | > - e1->managed_pages++ > + atomic_long_inc(&e1->managed_pages) > | > - z->managed_pages > + zone_managed_pages(z) > ) > > @@ > expression e,e1; > @@ > - e->managed_pages += e1 > + atomic_long_add(e1, &e->managed_pages) > > @@ > expression z; > @@ > - z.managed_pages > + zone_managed_pages(&z) > > Then, manually apply following change, > include/linux/mmzone.h > > - unsigned long managed_pages; > + atomic_long_t managed_pages; > > +static inline unsigned long zone_managed_pages(struct zone *zone) > +{ > + return (unsigned long)atomic_long_read(&zone->managed_pages); > +} > -- Michal Hocko SUSE Labs