mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 15:17:45 +00:00
Kernel: Don't rewrite the whole file on sys$msync
This commit is contained in:
parent
259f78545a
commit
c7b90fa7d3
3 changed files with 10 additions and 4 deletions
|
@ -35,11 +35,13 @@ SharedInodeVMObject::SharedInodeVMObject(SharedInodeVMObject const& other)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<void> SharedInodeVMObject::sync()
|
ErrorOr<void> SharedInodeVMObject::sync(off_t offset_in_pages, size_t pages)
|
||||||
{
|
{
|
||||||
SpinlockLocker locker(m_lock);
|
SpinlockLocker locker(m_lock);
|
||||||
|
|
||||||
for (size_t page_index = 0; page_index < page_count(); ++page_index) {
|
size_t highest_page_to_flush = min(page_count(), offset_in_pages + pages);
|
||||||
|
|
||||||
|
for (size_t page_index = offset_in_pages; page_index < highest_page_to_flush; ++page_index) {
|
||||||
auto& physical_page = m_physical_pages[page_index];
|
auto& physical_page = m_physical_pages[page_index];
|
||||||
if (!physical_page)
|
if (!physical_page)
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -18,7 +18,7 @@ public:
|
||||||
static ErrorOr<NonnullRefPtr<SharedInodeVMObject>> try_create_with_inode(Inode&);
|
static ErrorOr<NonnullRefPtr<SharedInodeVMObject>> try_create_with_inode(Inode&);
|
||||||
virtual ErrorOr<NonnullRefPtr<VMObject>> try_clone() override;
|
virtual ErrorOr<NonnullRefPtr<VMObject>> try_clone() override;
|
||||||
|
|
||||||
ErrorOr<void> sync();
|
ErrorOr<void> sync(off_t offset_in_pages = 0, size_t pages = -1);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual bool is_shared_inode() const override { return true; }
|
virtual bool is_shared_inode() const override { return true; }
|
||||||
|
|
|
@ -616,8 +616,12 @@ ErrorOr<FlatPtr> Process::sys$msync(Userspace<void*> address, size_t size, int f
|
||||||
if (!vmobject.is_shared_inode())
|
if (!vmobject.is_shared_inode())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
off_t offset = region->offset_in_vmobject() + address.ptr() - region->range().base().get();
|
||||||
|
|
||||||
auto& inode_vmobject = static_cast<Memory::SharedInodeVMObject&>(vmobject);
|
auto& inode_vmobject = static_cast<Memory::SharedInodeVMObject&>(vmobject);
|
||||||
TRY(inode_vmobject.sync());
|
// FIXME: Handle MS_ASYNC
|
||||||
|
TRY(inode_vmobject.sync(offset / PAGE_SIZE, size / PAGE_SIZE));
|
||||||
|
// FIXME: Handle MS_INVALIDATE
|
||||||
// FIXME: If msync() causes any write to a file, the file's st_ctime and st_mtime fields shall be marked for update.
|
// FIXME: If msync() causes any write to a file, the file's st_ctime and st_mtime fields shall be marked for update.
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue