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.5 required=3.0 tests=FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, 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 A8426C43603 for ; Fri, 20 Dec 2019 01:58:43 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 514A92467F for ; Fri, 20 Dec 2019 01:58:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 514A92467F Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=sina.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id E24858E0188; Thu, 19 Dec 2019 20:58:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DD5478E0184; Thu, 19 Dec 2019 20:58:42 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CC32F8E0188; Thu, 19 Dec 2019 20:58:42 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0146.hostedemail.com [216.40.44.146]) by kanga.kvack.org (Postfix) with ESMTP id B78B68E0184 for ; Thu, 19 Dec 2019 20:58:42 -0500 (EST) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with SMTP id 6B9C9180AD807 for ; Fri, 20 Dec 2019 01:58:42 +0000 (UTC) X-FDA: 76283860884.25.songs29_119e213d62d30 X-HE-Tag: songs29_119e213d62d30 X-Filterd-Recvd-Size: 2259 Received: from r3-18.sinamail.sina.com.cn (r3-18.sinamail.sina.com.cn [202.108.3.18]) by imf03.hostedemail.com (Postfix) with SMTP for ; Fri, 20 Dec 2019 01:58:40 +0000 (UTC) Received: from unknown (HELO localhost.localdomain)([221.219.1.122]) by sina.com with ESMTP id 5DFC2ACC00002FE8; Fri, 20 Dec 2019 09:58:38 +0800 (CST) X-Sender: hdanton@sina.com X-Auth-ID: hdanton@sina.com X-SMAIL-MID: 49987115073704 From: Hillf Danton To: linux-kernel Cc: linux-mm , Hillf Danton Subject: [RFC] mm: readahead: change ra size for random read Date: Fri, 20 Dec 2019 09:58:27 +0800 Message-Id: <20191220015827.8904-1-hdanton@sina.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.094491, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Set a smaller ra size for random read than contiguous one. It is deemed random if the lower-level device is unable to meet the read pattern even with its IO capability doubled. Signed-off-by: Hillf Danton --- --- a/mm/readahead.c +++ p/mm/readahead.c @@ -388,6 +388,7 @@ ondemand_readahead(struct address_space unsigned long max_pages =3D ra->ra_pages; unsigned long add_pages; pgoff_t prev_offset; + bool random =3D true; =20 /* * If the request exceeds the readahead window, allow the read to @@ -399,8 +400,34 @@ ondemand_readahead(struct address_space /* * start of file */ - if (!offset) - goto initial_readahead; + if (!offset) { +fill_ra: + ra->start =3D offset; + ra->size =3D random ? + min(bdi->io_pages, bdi->ra_pages) : + max(bdi->io_pages, bdi->ra_pages); + + ra->async_size =3D ra->size > req_size ? + ra->size - req_size : ra->size; + + return ra_submit(ra, mapping, filp); + } else { + unsigned long leap; + + if (offset > ra->start) + leap =3D offset - ra->start; + else + leap =3D ra->start - offset; + + /* + * anything other than page cache cannot help if it is + * too great a leap for the lower-level device to back + * up so feel free to put ra into fire + */ + random =3D leap > max(bdi->io_pages, bdi->ra_pages) * 2; + + goto fill_ra; + } =20 /* * It's the expected callback offset, assume sequential access.