From: Christoph Hellwig <hch@infradead.org>
To: Nicolas Pitre <nicolas.pitre@linaro.org>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>,
Christoph Hellwig <hch@infradead.org>,
linux-fsdevel@vger.kernel.org, linux-mm@kvack.org,
linux-embedded@vger.kernel.org, linux-kernel@vger.kernel.org,
Chris Brandt <Chris.Brandt@renesas.com>
Subject: Re: [PATCH v5 4/5] cramfs: add mmap support
Date: Fri, 6 Oct 2017 00:00:38 -0700 [thread overview]
Message-ID: <20171006070038.GA29142@infradead.org> (raw)
In-Reply-To: <20171006024531.8885-5-nicolas.pitre@linaro.org>
> + /* Don't map the last page if it contains some other data */
> + if (unlikely(pgoff + pages == max_pages)) {
> + unsigned int partial = offset_in_page(inode->i_size);
> + if (partial) {
> + char *data = sbi->linear_virt_addr + offset;
> + data += (max_pages - 1) * PAGE_SIZE + partial;
> + if (memchr_inv(data, 0, PAGE_SIZE - partial) != NULL) {
> + pr_debug("mmap: %s: last page is shared\n",
> + file_dentry(file)->d_name.name);
> + pages--;
> + }
> + }
> + }
Why is pgoff + pages == max_pages marked unlikely? Mapping the whole
file seems like a perfectly normal and likely case to me..
Also if this was my code I'd really prefer to move this into a helper:
static bool cramfs_mmap_last_page_is_shared(struct inode *inode, int offset)
{
unsigned int partial = offset_in_page(inode->i_size);
char *data = CRAMFS_SB(inode->i_sb)->linear_virt_addr + offset +
(inode->i_size & PAGE_MASK);
return memchr_inv(data + partial, 0, PAGE_SIZE - partial);
}
if (pgoff + pages == max_pages && offset_in_page(inode->i_size) &&
cramfs_mmap_last_page_is_shared(inode, offset))
pages--;
as that's much more readable and the function name provides a good
documentation of what is going on.
> + if (pages != vma_pages(vma)) {
here is how I would turn this around:
if (!pages)
goto done;
if (pages == vma_pages(vma)) {
remap_pfn_range();
goto done;
}
...
for (i = 0; i < pages; i++) {
...
vm_insert_mixed();
nr_mapped++;
}
done:
pr_debug("mapped %d out ouf %d\n", ..);
if (pages != vma_pages(vma))
vma->vm_ops = &generic_file_vm_ops;
return 0;
}
In fact we probably could just set the vm_ops unconditionally, they
just wouldn't be called, but that might be more confusing then helpful.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2017-10-06 7:00 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-06 2:45 [PATCH v5 0/5] cramfs refresh for embedded usage Nicolas Pitre
2017-10-06 2:45 ` [PATCH v5 1/5] cramfs: direct memory access support Nicolas Pitre
2017-10-06 2:45 ` [PATCH v5 2/5] cramfs: make cramfs_physmem usable as root fs Nicolas Pitre
2017-10-06 2:45 ` [PATCH v5 3/5] cramfs: implement uncompressed and arbitrary data block positioning Nicolas Pitre
2017-10-06 2:45 ` [PATCH v5 4/5] cramfs: add mmap support Nicolas Pitre
2017-10-06 7:00 ` Christoph Hellwig [this message]
2017-10-06 17:41 ` Nicolas Pitre
2017-10-06 2:45 ` [PATCH v5 5/5] cramfs: rehabilitate it Nicolas Pitre
2017-10-06 6:39 ` [PATCH v5 0/5] cramfs refresh for embedded usage Christoph Hellwig
2017-10-06 16:07 ` Chris Brandt
2017-10-06 16:30 ` Nicolas Pitre
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20171006070038.GA29142@infradead.org \
--to=hch@infradead.org \
--cc=Chris.Brandt@renesas.com \
--cc=linux-embedded@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=nicolas.pitre@linaro.org \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).