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 X-Spam-Level: X-Spam-Status: No, score=-1.0 required=3.0 tests=MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 90DD0C3815B for ; Mon, 20 Apr 2020 07:43:03 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 58C7C206B8 for ; Mon, 20 Apr 2020 07:43:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 58C7C206B8 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id CD2648E0007; Mon, 20 Apr 2020 03:43:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C34AA8E0003; Mon, 20 Apr 2020 03:43:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AFC2C8E0007; Mon, 20 Apr 2020 03:43:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0045.hostedemail.com [216.40.44.45]) by kanga.kvack.org (Postfix) with ESMTP id 9551C8E0003 for ; Mon, 20 Apr 2020 03:43:02 -0400 (EDT) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 537894DB2 for ; Mon, 20 Apr 2020 07:43:02 +0000 (UTC) X-FDA: 76727442204.30.eggs91_54b413b730002 X-HE-Tag: eggs91_54b413b730002 X-Filterd-Recvd-Size: 4529 Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by imf39.hostedemail.com (Postfix) with ESMTP for ; Mon, 20 Apr 2020 07:43:01 +0000 (UTC) Received: by mail-wr1-f67.google.com with SMTP id i10so10798393wrv.10 for ; Mon, 20 Apr 2020 00:43:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=sF2ypuY3Gdmd5kzt3EXRd0zAV/dXmWGqcAo5FF4k3Xw=; b=irUxAhS9NY7BHjtxGpUD2axOA9s6lMz1gNFerpUrhJMVXxWAN6f0XdRTXSxenT38h/ yi4KUCOrN+iTQ0Ytk7IUxMqrMyLM4gGyNt0bnfAO4PDNAbW8k1A1qxGKyXazN+r8q1JG +a9GmbdeqpxVbxLoxJcb3rb4kMCYuaPpvPZCHY9Uk4Y4/thdCX4LAd5jZEHCWovAoUbU 4WRq5b8u2KDluqGQlO4Yadfugfumj88mWQ8wlhOrB/QJjsD0SpKQkJfrQOaZXn0T0EPE dPDpKPIw/R3nj//5Kw+cnXAZgRzVgY4VOjKjDOZsh9sCcGtwJfTgDtp/FLZ4Uiw+cInv Dt4Q== X-Gm-Message-State: AGi0PuYIyW3/2Prk6j0UvOlMUDO8Hdip0bY67QzmiG5yZQmy3IAeHj+v cy1SrTYv0tfkawP1VM9OWBZyEe/2 X-Google-Smtp-Source: APiQypLMhjRx/cSxlhaI1OHqZRZ02PL+0G8XiQfIUtOKie/YYrXoLhNmAB/9m/lEL/hKcrbgXnu1UQ== X-Received: by 2002:adf:d0ca:: with SMTP id z10mr18737924wrh.172.1587368581094; Mon, 20 Apr 2020 00:43:01 -0700 (PDT) Received: from localhost (ip-37-188-130-62.eurotel.cz. [37.188.130.62]) by smtp.gmail.com with ESMTPSA id z8sm48540wrr.40.2020.04.20.00.42.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Apr 2020 00:43:00 -0700 (PDT) Date: Mon, 20 Apr 2020 09:42:54 +0200 From: Michal Hocko To: chenqiwu Cc: akpm@linux-foundation.org, linux-mm@kvack.org, chenqiwu Subject: Re: [PATCH] mm/memory: add refcount for special mapping page in copy_one_pte() Message-ID: <20200420074254.GF27314@dhcp22.suse.cz> References: <1587119514-29679-1-git-send-email-qiwuchen55@gmail.com> <20200417114312.GM26707@dhcp22.suse.cz> <20200417142618.GA31882@cqw-OptiPlex-7050> <20200417152331.GP26707@dhcp22.suse.cz> <20200418031207.GA9002@cqw-OptiPlex-7050> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200418031207.GA9002@cqw-OptiPlex-7050> 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 Sat 18-04-20 11:12:07, chenqiwu wrote: > On Fri, Apr 17, 2020 at 05:23:31PM +0200, Michal Hocko wrote: > > On Fri 17-04-20 22:26:18, chenqiwu wrote: > > > On Fri, Apr 17, 2020 at 01:43:12PM +0200, Michal Hocko wrote: > > > > On Fri 17-04-20 18:31:54, qiwuchen55@gmail.com wrote: > > > > > From: chenqiwu > > > > > > > > > > If we get a special mapping page like device mapping page or zero page > > > > > when copy_one_pte, it's necessary add the page refcount count. > > > > > > > > From the changelog it is not clear what is the actual problem and how > > > > the patch address it. Please be more verbose. > > > > > > > I don't find any actual problem, but I think there should be addressed > > > to update the page refcount for special mappings include devmap and zero > > > page instead of doing nothing else, since we copy the pte from one task > > > to the other. > > > > As Matthew pointed out, zero pages are special. Just check how > > vm_normal_page returns NULL (the same is the case for pte_devmap). This > > means, among other things that zap_pte_range which is called during > > munmap will only clear the pte but it doesn't operate on those pages so > > there is no put_page for your get_page here. > > > > I do realize that this might be a subtle details that might be > > confusing. On the other hand trying to formulate the specific problem > > and add an explanation of the fix in the changelog could have revealed > > this. It is really trivial to generate mappings backed by zero pages and > > if the reference count was not handled properly then it would blow up > > pretty quickly. > > > I agree. But I can't see where to put the normal page refcount back > in zap_pte_range(), is there an imbalnace between copy_one_pte() and > zap_pte_range()? No, there is no imbalance. The reference counter handling is very well hidden. Each page gets tracked by __tlb_remove_page and later handled tlb_flush_mmu. That all is done to optimize tlb flushing which is necessary when pages are freed. -- Michal Hocko SUSE Labs