Skip to content

Commit b08ef6f

Browse files
Evan Greenandersson
authored andcommitted
Use fdatasync instead of O_SYNC on storage
Opening the backing files with O_SYNC makes things really slow. So slow in fact that the modem times out after 10 seconds waiting for the last EFS sync to go through. I think this takes forever because rmtfs is doing 512-byte reads and writes. One option would be to make this bigger. But a better option is to not use O_SYNC, but explicitly do an fdatasync() after the iovec operation is complete. This is better because 1) it's way faster, we no longer see 10-12 second delays at rebooto time, and 2) partial syncs of the EFS file aren't useful anyway. Use fdatasync() as opposed to fsync() since it's not important for the metadata to be synced, just the file contents. Signed-off-by: Evan Green <[email protected]>
1 parent 293ab8b commit b08ef6f

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

rmtfs.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,10 @@ static void rmtfs_iovec(int sock, struct qrtr_packet *pkt)
220220
respond:
221221
dbgprintf("[RMTFS] iovec %d, %sforced => (%d:%d)\n", caller_id, force ? "" : "not ",
222222
resp.result.result, resp.result.error);
223+
224+
if (is_write)
225+
storage_sync(rmtfd);
226+
223227
for (i = 0; i < num_entries; i++) {
224228
dbgprintf("[RMTFS] %s %d:%d 0x%x\n", is_write ? "write" : "read",
225229
entries[i].sector_addr,

rmtfs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ int storage_get_error(const struct rmtfd *rmtfd);
3434
void storage_exit(void);
3535
ssize_t storage_pread(const struct rmtfd *rmtfd, void *buf, size_t nbyte, off_t offset);
3636
ssize_t storage_pwrite(struct rmtfd *rmtfd, const void *buf, size_t nbyte, off_t offset);
37+
int storage_sync(struct rmtfd *rmtfd);
3738

3839
int rproc_init(void);
3940
int rproc_start(void);

storage.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ struct rmtfd *storage_open(unsigned node, const char *path)
122122
fspath = alloca(pathlen);
123123
snprintf(fspath, pathlen, "%s/%s", storage_dir, file);
124124
if (!storage_read_only) {
125-
fd = open(fspath, O_RDWR | O_SYNC);
125+
fd = open(fspath, O_RDWR);
126126
if (fd < 0) {
127127
saved_errno = errno;
128128
fprintf(stderr, "[storage] failed to open '%s' (requested '%s'): %s\n",
@@ -245,6 +245,14 @@ ssize_t storage_pwrite(struct rmtfd *rmtfd, const void *buf, size_t nbyte, off_t
245245
return nbyte;
246246
}
247247

248+
int storage_sync(struct rmtfd *rmtfd)
249+
{
250+
if (storage_read_only)
251+
return 0;
252+
253+
return fdatasync(rmtfd->fd);
254+
}
255+
248256
static int storage_populate_shadow_buf(struct rmtfd *rmtfd, const char *file)
249257
{
250258
ssize_t len;

0 commit comments

Comments
 (0)