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=-3.6 required=3.0 tests=BAYES_00,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 EE87EC4346E for ; Tue, 22 Sep 2020 02:13:09 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 7868123A75 for ; Tue, 22 Sep 2020 02:13:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="HEVTFy55" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7868123A75 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 CD95E90001B; Mon, 21 Sep 2020 22:13:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CB05E900012; Mon, 21 Sep 2020 22:13:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BED5B90001B; Mon, 21 Sep 2020 22:13:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0194.hostedemail.com [216.40.44.194]) by kanga.kvack.org (Postfix) with ESMTP id A19DF900012 for ; Mon, 21 Sep 2020 22:13:08 -0400 (EDT) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 6E2DF8249980 for ; Tue, 22 Sep 2020 02:13:08 +0000 (UTC) X-FDA: 77289074856.01.space57_3d16a562714a Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin01.hostedemail.com (Postfix) with ESMTP id 3A74310049A69 for ; Tue, 22 Sep 2020 02:13:08 +0000 (UTC) X-HE-Tag: space57_3d16a562714a X-Filterd-Recvd-Size: 4983 Received: from mail-io1-f66.google.com (mail-io1-f66.google.com [209.85.166.66]) by imf11.hostedemail.com (Postfix) with ESMTP for ; Tue, 22 Sep 2020 02:13:07 +0000 (UTC) Received: by mail-io1-f66.google.com with SMTP id g128so17860824iof.11 for ; Mon, 21 Sep 2020 19:13:07 -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=jBt5+fo8B0fT5POH64X+uz0syHvH1xM7+s+CX9tQZY4=; b=HEVTFy55TblTeFFL6V5clUbtA38j50vNzknnGDK/BYk2krbCOH9OIXY1O0PYa+GuZY YyRVieNFvVR7PbmsTSvARBqNo5H9c6Sv+MQtFDZxaf4UZVLZXQWFUO0NAVR0cQwzgj6G nXWC5iTl4XvnvG0uTZifa0DcEcc+GDwYmZF3rtACTcn5EWZ9I0L9/SJVPeYIyr8G7/Z1 myil0Bq4JkwT7O1SuPUL+MkzfrytBbssnerkdLrUzOrQeSCKVXMyIhtbCV0aWJ3c7kBF OUx0to+ll1/OwcrNSFAZPDBF7Fh/dPhK4DGq+iiejw39vSIn+s1SrEtF5QJjeS4qBnPD MNrA== 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=jBt5+fo8B0fT5POH64X+uz0syHvH1xM7+s+CX9tQZY4=; b=tiHQvX32YNnDxwpA47KYd8luoDN8/sU7chIOd5+prt6zThQTWrWabKQ6HrFUXKL/vF Sol+RKYYE49fp9Ua5tX5uF8R4E4rOiXgJJvy+1lbEDT2SiYwBI+I0SZ44oMPJY7Arr7C uOe36f/vo8wJvUnZ2PP7s8hAvDZwiwzbDvqXTn85GgMViMfSHcuz2Dz12F+alR/+qS9z qCjqngbzIM7j4kmf7fc+0vIb5IBDevjvVDkCFSAo13if67T/cLXPiNzkDut99HiAVvaS jZxvk383QJ5sLOqJde4OauPRt61qe/bnxe0UOB8MHbo/btCi/7qc5+jw95y5RuDOa0HB aYHQ== X-Gm-Message-State: AOAM532U5ZYulaZkcFYqOsZnWQUWTsHklfcOZF+py7xed9n9WJJFjCXm X2Vpfi0wkgH+KY4QMI4GgqMBhT8ORYj6sBXh4yg= X-Google-Smtp-Source: ABdhPJxU2TGhu6EaOyipbnXotKKGdMfcXXGv1uEqrfL9Quj2OGbUQx7CwUb3moww/M98ofmjBjcJksqIFgzlO4NuTfA= X-Received: by 2002:a5e:dc08:: with SMTP id b8mr1756718iok.13.1600740787093; Mon, 21 Sep 2020 19:13:07 -0700 (PDT) MIME-Version: 1.0 References: <20200921014317.73915-1-laoar.shao@gmail.com> <20200921223430.GI3117@suse.de> In-Reply-To: <20200921223430.GI3117@suse.de> From: Yafang Shao Date: Tue, 22 Sep 2020 10:12:31 +0800 Message-ID: Subject: Re: [PATCH] mm, fadvise: improve the expensive remote LRU cache draining after FADV_DONTNEED To: Mel Gorman Cc: Andrew Morton , Johannes Weiner , Michal Hocko , Linux MM Content-Type: text/plain; charset="UTF-8" X-Bogosity: Ham, tests=bogofilter, spamicity=0.001342, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Tue, Sep 22, 2020 at 6:34 AM Mel Gorman wrote: > > On Mon, Sep 21, 2020 at 09:43:17AM +0800, Yafang Shao wrote: > > Our users reported that there're some random latency spikes when their RT > > process is running. Finally we found that latency spike is caused by > > FADV_DONTNEED. Which may call lru_add_drain_all() to drain LRU cache on > > remote CPUs, and then waits the per-cpu work to complete. The wait time > > is uncertain, which may be tens millisecond. > > That behavior is unreasonable, because this process is bound to a > > specific CPU and the file is only accessed by itself, IOW, there should > > be no pagecache pages on a per-cpu pagevec of a remote CPU. That > > unreasonable behavior is partially caused by the wrong comparation of the > > number of invalidated pages and the number of the target. For example, > > if (count < (end_index - start_index + 1)) > > The count above is how many pages were invalidated in the local CPU, and > > (end_index - start_index + 1) is how many pages should be invalidated. > > The usage of (end_index - start_index + 1) is incorrect, because they > > are virtual addresses, which may not mapped to pages. We'd better use > > inode->i_data.nrpages as the target. > > > > How does that work if the invalidation is for a subset of the file? > I realized it as well. There are some solutions to improve it. Option 1, take the min as the target. - if (count < (end_index - start_index + 1)) { + target = min_t(unsigned long, inode->i_data.nrpages, + end_index - start_index + 1); + if (count < target) { lru_add_drain_all(); Option 2, change the prototype of invalidate_mapping_pages and then check how many pages were skipped. + struct invalidate_stat { + unsigned long skipped; // how many pages were skipped + unsigned long invalidated; // how many pages were invalidated +}; - unsigned long invalidate_mapping_pages(struct address_space *mapping, +unsigned long invalidate_mapping_pages(struct address_space *mapping, struct invalidate_stat *stat, I prefer option 2. What do you think ? -- Thanks Yafang