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.1 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED 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 C9F59C433DF for ; Wed, 24 Jun 2020 20:23:17 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8E3B72080C for ; Wed, 24 Jun 2020 20:23:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gsLANbH8" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8E3B72080C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id E38E86B0002; Wed, 24 Jun 2020 16:23:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DEA2B6B0008; Wed, 24 Jun 2020 16:23:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CB0E76B0023; Wed, 24 Jun 2020 16:23:16 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0237.hostedemail.com [216.40.44.237]) by kanga.kvack.org (Postfix) with ESMTP id B032A6B0002 for ; Wed, 24 Jun 2020 16:23:16 -0400 (EDT) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 4F91F1EE6 for ; Wed, 24 Jun 2020 20:23:16 +0000 (UTC) X-FDA: 76965229992.18.seat34_050f03726e47 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin18.hostedemail.com (Postfix) with ESMTP id 28B6F100EDBC7 for ; Wed, 24 Jun 2020 20:23:16 +0000 (UTC) X-HE-Tag: seat34_050f03726e47 X-Filterd-Recvd-Size: 4545 Received: from mail-ej1-f66.google.com (mail-ej1-f66.google.com [209.85.218.66]) by imf05.hostedemail.com (Postfix) with ESMTP for ; Wed, 24 Jun 2020 20:23:15 +0000 (UTC) Received: by mail-ej1-f66.google.com with SMTP id n24so3771204ejd.0 for ; Wed, 24 Jun 2020 13:23:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=3N8Iq+jMa7Wr2bmXCR98pNboSajMlgVPuPMQP9CFTnI=; b=gsLANbH8oUM6Oqn4g+49U/gczDfj3IaDXZ4bdqAM970FR1Kzectrc0SAtNLpsQY0LF JrlPKLo+goWwEjS3lM+M4CiRFku+WAyJCHeZKt8JxtukWcMI1AlskIDY8bRU6xfll5JQ XEvJ7WrIDuTPmB/Q+e3RtTXXOV9jZMPybKMGzBGZdgkOAofL1rY6yrLx0AkYkFvl0LrR vM55HjIBf9SnCeu26+5a4DmCplfZH797uDptMTtp7UwjTGM0qKFaPsGMDtD83p29fAPd g/7B9Efx/ARDqWtNzohLVDa6iG/gtZ4PBo3rSCtCXq7uMEp+BNPAZ167Fdm/Z/uvTmum NzAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=3N8Iq+jMa7Wr2bmXCR98pNboSajMlgVPuPMQP9CFTnI=; b=RjwgVJ9ldzve1aYS89LzNE4Pdl+RNQcBEOmmURRHMOMaHJi4TmfJbU4lBH/ZYseTSo 0+DhzERviLqT5oGmP21wepZOOb3rSWvp6cAh0RywvZJSVOIByQBAFFq/H5YdW3gmq9JH NpyM/6hqyPyjQCtj6lTQVUv3XoJtjTz3uzG+0y10ubywrafSKlN65FNJswnYATExM/st ocZ+taehLKCVOhUi/s+1Yj1yAQms1ZTvmOuX98bV28f9fUVgoUkPbf9Xi+T2EO0HGIzm Cc+pfHCRsjwZoj2wx78xh4xl8RltYaxS1gUlguGRMwCcHmQQ9vtQJ+i9XdFRO8v7BIxJ I+0w== X-Gm-Message-State: AOAM532JdV+szkVBnHtSyNexPCAWkqFPS6NTMUJ9q33OXJvsLTjHTh+l ZcwmVWhIrNsfSt2ILcdyuACioromSeZcBY4MEVU= X-Google-Smtp-Source: ABdhPJyZ0A3i4KIhrEMZ2Pt4CNQKY0ZyDPCM7n8IH+lqiA4Y4W2gkj1dII1B79yKWD+r3QyLP7FE2RgA1MTiJtGowBs= X-Received: by 2002:a17:907:2058:: with SMTP id pg24mr18819307ejb.79.1593030194663; Wed, 24 Jun 2020 13:23:14 -0700 (PDT) MIME-Version: 1.0 References: <20200624191417.16735-1-chris@chris-wilson.co.uk> <20200624192116.GO6578@ziepe.ca> In-Reply-To: <20200624192116.GO6578@ziepe.ca> From: Yang Shi Date: Wed, 24 Jun 2020 13:23:02 -0700 Message-ID: Subject: Re: [PATCH] mm: Skip opportunistic reclaim for dma pinned pages To: Jason Gunthorpe Cc: Chris Wilson , Linux MM , Linux Kernel Mailing List , intel-gfx@lists.freedesktop.org, Andrew Morton , Jan Kara , =?UTF-8?B?SsOpcsO0bWUgR2xpc3Nl?= , John Hubbard , Claudio Imbrenda , "Kirill A . Shutemov" Content-Type: text/plain; charset="UTF-8" X-Rspamd-Queue-Id: 28B6F100EDBC7 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam04 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 Wed, Jun 24, 2020 at 12:21 PM Jason Gunthorpe wrote: > > On Wed, Jun 24, 2020 at 08:14:17PM +0100, Chris Wilson wrote: > > A general rule of thumb is that shrinkers should be fast and effective. > > They are called from direct reclaim at the most incovenient of times when > > the caller is waiting for a page. If we attempt to reclaim a page being > > pinned for active dma [pin_user_pages()], we will incur far greater > > latency than a normal anonymous page mapped multiple times. Worse the > > page may be in use indefinitely by the HW and unable to be reclaimed > > in a timely manner. > > A pinned page can't be migrated, discarded or swapped by definition - > it would cause data corruption. > > So, how do things even get here and/or work today at all? I think the > explanation is missing something important. The __remove_mapping() will try to freeze page count if the count is expected otherwise just not discard the page. I'm not quite sure why the check is done that late, my wild guess is to check the refcount at the last minute so there might be a chance the pin gets released right before it. But I noticed a bug in __remove_ampping() for THP since THP's dma pinned count is recorded in the tail page's hpage_pinned_refcount instead of refcount. So, the refcount freeze might be successful for pinned THP. Chris's patch could solve this issue too, but I'm not sure if it is worth backing earlier once dma pinned page is met. If it is worth, the follow-up question is why not just skip such page in scan phase? > > Jason >